/ Published in: SAS

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
*** ORDER MACRO ***; * This macro creates a format that will order PROC REPORT across columns; * according to the order the values are input, see examples below; * &order is a pipe(|) delimited list of values to be ordered; * &fmtname is the name of the format statement to be output; %macro order_fmt(fmtname=,order=); %local icol ncol nspace ispace space; /* Start defining format */ proc format; value &fmtname /* Loop over the columns specified in &order */ %let ncol = %sysfunc(countw(%bquote(&order),|)); %do icol = 1 %to &ncol; /* Prefix formatted values with spaces to enforce ordering*/ %let nspace = %eval(&ncol + 1 - &icol); %let space = %str(); %do ispace = 1 %to &nspace; %let space = &space%str( ); %end; /* Format line - TRIM assumes that input data does not have prefix spaces*/ "%qleft(%qtrim(%qscan(&order,&icol,|)))" = "&space%qleft(%qtrim(%qscan(&order,&icol,|)))" %end; ; run; %mend order_fmt;
Comments
