BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Fettah
Fluorite | Level 6

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 
;
1 ACCEPTED SOLUTION

Accepted Solutions
japelin
Rhodochrosite | Level 12

data want;
  set have;
  do num=start to end;
    output;
  end;
run;

try this code.

View solution in original post

4 REPLIES 4
japelin
Rhodochrosite | Level 12

data want;
  set have;
  do num=start to end;
    output;
  end;
run;

try this code.

Fettah
Fluorite | Level 6
Works like a charm, thank you!
ballardw
Super User

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.

 

Fettah
Fluorite | Level 6

Woops. that was a typo. Thanks for pointing it out.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 453 views
  • 0 likes
  • 3 in conversation