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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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: