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.
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 25. 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.