🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 10-20-2021 03:22 PM
(1456 views)
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.
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug
"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings
SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug
"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings
SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug
"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings
SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug
"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings
SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The solution is simple and worked easily. Thank you.