Hello,
I have data in the following structure:
InitialString | FirstNumber | SecondNumber |
14-17 | 14 | 17 |
15-17 | 15 | 17 |
16-17 | 16 | 17 |
14-16 | 14 | 16 |
I'm hoping to create a delimited string that contains the full sequence of numbers between "FirstNumber" and "SecondNumber", inclusively, given that the initial string could contain a wide variety of "FirstNumber" and "SecondNumber" values. See desired outcome below:
InitialString | FirstNumber | SecondNumber | FinalString |
14-17 | 14 | 17 | 14; 15; 16; 17 |
15-17 | 15 | 17 | 15; 16; 17 |
16-17 | 16 | 17 | 16; 17 |
14-16 | 14 | 16 | 14; 15; 16 |
Please let me know how I might accomplish this task automatically. The simpler, the better. Thank you.
try this:
data have;
input InitialString $ FirstNumber SecondNumber;
cards;
14-17 14 17
15-17 15 17
16-17 16 17
14-16 14 16
;
run;
proc print;
run;
data want;
set have;
length FinalString $ 200; /* set accordingly to your data */
do _N_ = FirstNumber to SecondNumber;
FinalString = catx("; ",FinalString,_N_);
end;
run;
proc print;
run;
Bart
try this:
data have;
input InitialString $ FirstNumber SecondNumber;
cards;
14-17 14 17
15-17 15 17
16-17 16 17
14-16 14 16
;
run;
proc print;
run;
data want;
set have;
length FinalString $ 200; /* set accordingly to your data */
do _N_ = FirstNumber to SecondNumber;
FinalString = catx("; ",FinalString,_N_);
end;
run;
proc print;
run;
Bart
The solution is simple and worked easily. Thank you.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.