@Trishjais data input; input lines$20.; lines_=lines; /*temporary replacements to avoid errors at macro processing*/ lines_=translate(lines, '2', '.'); lines_=translate(lines_, '1', '@'); lines; Michael Jack@gmail.com AO987JJ 9650234567 ; run; /*dynamically create macro variables from the above data*/ data _null_; set input; call symputx("val"||left(_N_), lowcase(lines_)); run; /*empty data set to use at step 4 of macro def*/ data final; length str $20; str=""; run; /*use parmbuff to support random parameters at macro call*/ %macro result/parmbuff; /*create length macro var based on the parameters passed to this macro def. adding '1' is required since shuffled indices are followed by data set name*/ %let length = %eval(1+%sysfunc(countc(&syspbuff, ','))); %let str=; /*loop to replace chars*/ %do i=2 %to &length; /*extracting specified(random) chars from the original string*/ %let str = &str.%substr(%scan(&syspbuff, 1), %scan(&syspbuff, &i), 1); %end; /*storing each shuffled value in a separate data set*/ data ds_%scan(&syspbuff, 1); /*optional length statement to avoid concatenation warnings*/ length str $20; str="&str"; run; /*to join with other calls - step 4*/ data final(where=(not missing(str))); set final ds_%scan(&syspbuff, 1); run; /*macro name after %mend is optional*/ %mend result; /*pass macro vars with desired shuffle order*/ /*semicolon at the end of macro call is optional*/ %result(&val1, 7, 1, 2, 3, 4, 5, 6) %result(&val2, 4, 3, 1, 2, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14) %result(&val3, 3, 6, 5, 4, 7, 2, 1) %result(&val4, 2, 1, 3, 6, 4, 6, 3, 1, 7, 10) /*improvements*/ data final; set final; /*back to normal*/ str=translate(str, '@', '1'); str=translate(str, '.', '2'); run; data output(drop=lines_ rename=(lines=input str=output)); /*make it side by side and some cosmetic changes*/ merge input final; if findc(str, '@') then str=lowcase(str); else if anydigit(str) then str=upcase(str); else str=propcase(str); run; /*deleting extra data sets from work lib to save ram*/ proc datasets lib=work nolist; save output; quit;
... View more