BookmarkSubscribeRSS Feed
Aayushi_17
Quartz | Level 8

Hi how to get the desired output if we have input like this shown below

 

Input
walking_stick, aids_used_for_dressing
walking_frame, other
reaching, shopping_and_housework
rising, walking
reaching, gripping_and_opening_things, shopping_and_housework
reaching, gripping_and_opening_things
raised_toilet_seat, jar_opener_for_jars_previously_opened, bath_rail, long_handled_appliances_in_bathroom

 

output like this :

Output
walking_stick
 aids_used_for_dressing
walking_frame
 other
reaching
 shopping_and_housework
rising
 walking
reaching
 gripping_and_opening_things
 shopping_and_housework
reaching
 gripping_and_opening_things
raised_toilet_seat
 jar_opener_for_jars_previously_opened
 bath_rail
 long_handled_appliances_in_bathroom

 

by separating values with comma

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

Try this

 

data have;
input string $ 1-200;
infile datalines truncover;
datalines;
walking_stick, aids_used_for_dressing                                                                     
walking_frame, other                                                                                      
reaching, shopping_and_housework                                                                          
rising, walking                                                                                           
reaching, gripping_and_opening_things, shopping_and_housework                                             
reaching, gripping_and_opening_things                                                                     
raised_toilet_seat, jar_opener_for_jars_previously_opened, bath_rail, long_handled_appliances_in_bathroom 
;

data want(keep = w);
   set have;

   do i = 1 to countw(string, ', ');
      w = scan(string, i, ', ');
      output;
   end;
run;
Phil_NZ
Barite | Level 11

You can follow the code given by @PeterClemmensen 

Just another document you can give it a go about your issue ( https://blogs.sas.com/content/iml/2016/07/11/break-sentence-into-words-sas.html#:~:text=The%20COUNTW....)

You will see the solution for a more comprehensive question relating to your issue.

Cheers.

 

Thank you for your help, have a fabulous and productive day! I am a novice today, but someday when I accumulate enough knowledge, I can help others in my capacity.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1078 views
  • 2 likes
  • 3 in conversation