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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 563 views
  • 2 likes
  • 3 in conversation