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

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 14735 views
  • 3 likes
  • 11 in conversation