Can you please advice how I might create observations containing a range of values, where the range is specified by two columns: start, and end.
Essentially, how do I convert this:
data have; input start end; datalines; 100 103 301 305 336 338 ;
to this:
data want; input start end num; datalines; 100 120 100 100 120 101 100 120 102 301 305 301 301 305 302 301 305 303 301 305 304 301 305 305 336 338 336 336 338 337 336 338 338 ;
data want;
set have;
do num=start to end;
output;
end;
run;
try this code.
data want;
set have;
do num=start to end;
output;
end;
run;
try this code.
So, how does "end" get transformed to 120, 305 and 338 in that output?
And are you sure that you don't want a
100 120 103
in the output as well?
Without changing the "end" which you did not provide any logic for this is the basic approach
data want; set have; do num=start to end; output; end; run;
The explicit OUTPUT statement means that data is written into the output data set each time it executes, once for each value in the Do loop.
Woops. that was a typo. Thanks for pointing it out.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.