☑ This topic is solved.
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 07-28-2022 12:21 PM
(2328 views)
I have a list of values separated by space.
%let list = A B C;
I would like to create a single-column dataset.
Col1 |
A |
B |
C |
Thanks in advance!
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data want;
do i = 1 to countw("&list.");
col1 = scan("&list.",i);
output;
end;
drop i;
run;
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data want;
do i = 1 to countw("&list.");
col1 = scan("&list.",i);
output;
end;
drop i;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You may want to consider specifying a length for Col1 variable based on your knowledge of the starting list. The default length using @Kurt_Bremser's solution will create a variable that is the length of the entire list. If you have many values that could mean that you have a variable of several hundred (or thousand) characters even though the longest value of interest is only one or two or some other number much smaller than thousands.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can also let SAS determine the minimum required length of Col1:
data wide / view=wide;
retain c1-c%sysfunc(countw(&list,%str( )))
("%sysfunc(tranwrd(&list,%str( ),%str(" ")))");
run;
proc transpose data=wide out=want(drop=_:);
var c:;
run;