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!
data want;
do i = 1 to countw("&list.");
col1 = scan("&list.",i);
output;
end;
drop i;
run;
data want;
do i = 1 to countw("&list.");
col1 = scan("&list.",i);
output;
end;
drop i;
run;
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.
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.