BookmarkSubscribeRSS Feed
SPChoudary
Fluorite | Level 6

Here is another example which will work in all scenarios.

 

data inds;
 invar = "There was once a merchant who employed many carpenters and masons to build a temple in his garden. Regularly, they would start work in the morning; The Monkey And The Wedge - Panchatantra Story Pictureand take a break for the mid-day meals, and return to resume work till evening. One day, a group of monkey arrived at the site of the building and watched the workers leaving for their mid-day meals. One of the carpenters was sawing a huge log of wood. Since, it was only half-done; he placed a wedge in between to prevent the log from closing up. He then went off along with the other workers for his meal.";
 output;
 invar = "Small string";
 output;
 invar = " ";
 output;
run;

 

data outds_row;
 set inds;
 obs_seq = _n_;
 length outvar $200;
 sub_invar = invar;
 itrno = 0;
 do until (sub_invar = " ");
  dlmpos = 199 - lengthn(scan(reverse(substrn(sub_invar, 1, 200)), 1, " "));
  outvar = strip(substrn(sub_invar, 1, dlmpos));
  sub_invar = strip(substrn(sub_invar, dlmpos + 1));
  itrno + 1;
  output;
 end;
 drop sub_invar dlmpos;
run;

 

proc sort data = outds_row;
 by obs_seq itrno;
run;

 

proc transpose data = outds_row out = outds_col prefix = outvar;
 by obs_seq;
 id itrno;
 var outvar;
run;

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!
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 15 replies
  • 11259 views
  • 3 likes
  • 11 in conversation