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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 15 replies
  • 14610 views
  • 3 likes
  • 11 in conversation