Below is the dataset that I have:
I want to transform it like the data below:
I tried the code below but it isn't working:
data want;
set ref_table;
i=1;
do until (missing(pre_req));
pre_req=scan(pre_req,i,",");
i+1;
end;
run;
May I know how to modify this?
You are overwriting pre_req in the loop, that can't work as expected. You need to extract the values to a new variable. Code is untested.
data want;
set ref_table;
do i = 1 to countw(pre_req, ',');
new_pre_req = scan(pre_req, i, ",");
output;
end;
drop pre_req;
rename new_pre_req = pre_req;
run;
You are overwriting pre_req in the loop, that can't work as expected. You need to extract the values to a new variable. Code is untested.
data want;
set ref_table;
do i = 1 to countw(pre_req, ',');
new_pre_req = scan(pre_req, i, ",");
output;
end;
drop pre_req;
rename new_pre_req = pre_req;
run;
use next code:
data want;
set ref_table(rename=(pre_reg=reqs));
do i=1 to countw(reqs);
pre_req = scan(reqs,i,",");
outputl
end;
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.