BookmarkSubscribeRSS Feed
Sowmya12
Fluorite | Level 6
Suppose if dataset contains

Id         ict
102     4
103      5,7
;
run;



The output dataset should be

Id       ict
102    4
103     5
103      7


Suggest me how can I get the output as mentioned above
3 REPLIES 3
japelin
Rhodochrosite | Level 12

How about this code?

data have;
  length Id 8 ict $8;
  infile datalines dlm=' ';
  input id ict;
datalines;
102 4
103 5,7
;
run;

data want;
  set have;
  tmp_cnt=count(ict,',')+1;
  tmp_ict=ict;
  do i=1 to tmp_cnt;
    ict=scan(tmp_ict,i,',');
    output;
  end;
 
  drop tmp_: i;
run;

(modified.) 

Kurt_Bremser
Super User

You can simplify this with the use of dataset options and use of the COUNTW function in the DO statement:

data want;
set have (rename=(ict=_ict));
do i = 1 to countw(_ict,",");
  ict = scan(_ict,i,",");
  output;
end;
drop i _ict;
run;
Kurt_Bremser
Super User

PS if you want numbers, add an INPUT function:

data want;
set have (rename=(ict=_ict));
do i = 1 to countw(_ict,",");
  ict = input(scan(_ict,i,","),32.);
  output;
end;
drop i _ict;
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
  • 3 replies
  • 341 views
  • 4 likes
  • 3 in conversation