You can fill in (or compute) intra range gaps using basic comparisons, some holding variables and a retained variable.
Example:
Presume no ranges overlap and are order low start first.
data have;
input id x1 x2; datalines;
1 3 7
1 11 14
2 4 9
2 15 18
3 1 11
4 11 20
5 1 2
5 3 4
5 5 9
5 10 20
;
data want;
set have;
by id;
length type $6;
* fill in ranges for every integer 1 through 20;
if first.id then do;
bot = 1;
retain bot;
end;
if bot < x1 then do;
hold1 = x1;
hold2 = x2;
x1 = bot;
x2 = hold1 - 1;
type = 'gap -';
output;
x1 = hold1;
x2 = hold2;
type = 'have';
bot = x2 + 1;
output;
end;
else if x1 <= bot <= x2 then do;
bot = x2 + 1;
type = 'have';
output;
end;
if last.id and 20 >= bot > x2 then do;
type = 'gap +';
x1 = bot;
x2 = 20;
output;
end;
keep type id x1 x2 bot;
run;
CLICK HERE to find out more related problems solutions.