BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
iSAS
Quartz | Level 8

Below is the dataset that I have:

iSAS_0-1594975761747.png

I want to transform it like the data below:

iSAS_1-1594976159790.png

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

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;

 

View solution in original post

2 REPLIES 2
andreas_lds
Jade | Level 19

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;

 

Shmuel
Garnet | Level 18

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 600 views
  • 1 like
  • 3 in conversation