Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**********************************************************
- *
- * Program Name : dec_align.sas
- * Level / Study :
- * Type : Macro
- * Description : Fix aligment issues
- *
- *
- * Author : Leanne McNaught
- * Date Created : 27OCT2017
- * Program Status : Draft
- *
- *
- **********************************************************
- * Amended :
- * Date Amended :
- * Amended By :
- **********************************************************/
- %macro dec_align(dsin=, test=, aval=, dsout=);
- proc sql noprint;
- select type
- into: type
- from sashelp.vcolumn
- where libname= "WORK" and memname= %upcase("&dsin") and name= %upcase("&aval");
- quit;
- data check;
- set &dsin. %if &type = num %then %do;(rename=(&aval=test))%end;;
- n= _n_;
- %if &type = num %then %do;
- &aval= strip(put(test, best.));
- %end;
- run;
- data check1;
- set check;
- len= length(&aval);
- dec= find(&aval, ".");
- if dec ne 0 then postlen= length(substr(&aval, dec, len)) - 1;
- else postlen= .;
- if dec ne 0 then prelen= length(substr(&aval, 1, dec)) - 1;
- else prelen= length(substr(&aval, 1, len));
- run;
- proc sql noprint;
- select max(prelen)
- into: max
- from check1;
- select count(*)
- into: count trimmed
- from check1;
- quit;
- data check1a;
- set check1;
- max= &max;
- if postlen ne . then do;
- maxlen= max + postlen + 1;
- decput= strip(put(maxlen, best.)) || "." || strip(put(postlen, best.));
- end;
- run;
- data &dsout;
- set check1a;
- length &aval._dec $200;
- do i = 1 to &count;
- if n= i then do;
- if postlen= . then &aval._dec= put(input(&aval, best.), &max..);
- else if postlen ne . then do;
- &aval._dec= putn(input(&aval,best.), decput);
- end;
- end;
- end;
- run;
- %mend dec_align;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement