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.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: