Thank you guys for ur ideas... But i wanted a macro like simple program which accepts a input sentence and creates sub variables with small length like 50 bytes. Proc rank seems to be a excellent idea but the grouping needs to done in trial and error method based on the sub variable length to get the accurate results. So i think its not usefull for automating. Please go through my program below and through me some ideas to improve it. ***Input sentence***; %let sentence=We mostly use the default behavior of the DATA STEP to create working code. However, certain common tasks are made easier by overriding the default behavior. In the Pharmaceutical Industry one such common task is LOCF.; ***Counting the words***; %let nn=%sysfunc(countw("&sentence")); ***Macro for splitting the sentence into separate variable***; %macro word_split ( sub_var_name=txt, /*sub variable name*/ sub_var_len=50, /*length of sub variable*/ No_sub_var=4); /*No of sub variable to be created*/ data new; length s $200 &sub_var_name.1-&sub_var_name.&No_sub_var $&sub_var_len; Sentence="&sentence"; array a(*) $20 w1-w&nn; /*Splitting the sentence into individual words*/ do i= 1 to &nn; a(i)=scan("&sentence",i); end; do i= 1 to &nn; retain s; a1=s; s=catx (" ",trim(a1),trim(a(i))); /*Concatenating the words one by one and*/ nlen=length(s); /*calculating its length*/ if nlen gt %sysevalf((&sub_var_len)-10) then do; %macro split_var (); /*Macro for creating sub variable with values*/ %do i= 1 %to &No_sub_var; if (length(trim(&sub_var_name.&i)) le 1) then do; &sub_var_name.&i = s; s=" "; nlen=.; end; %end; %mend; %split_var (); end; if nlen ne . then &sub_var_name.&No_sub_var = s; end; keep Sentence &sub_var_name.1-&sub_var_name.&No_sub_var; run; %mend; ***end of Macro***; %word_split (sub_var_name=var, sub_var_len=50, No_sub_var=5)
... View more