Hi,
Would someone have guidance for how to apply formatting in the following scenario?:
I have an input dataset which applies time formats for certain time variables. My understanding is the variables don't retain the their formats when, in a new data set, I create a variable stacking these time variables alongside other-format numeric variables; In other words, I stack different input datasets, where each has the variable, say, "E" on top of each other but where each will have a different formatted input variable for the new variable, "E" being created
Q--> How do I apply formatting so that each of the values within this new data set's created variable is formatted differently and correctly?
More specifically, I apply the following macro below where I start off with an input dataset (&input) with input variable, (&var), and end up with an output dataset (cont_&byvar.&odata.) which has output vars named E, M, H, etc. After stacking a number of these datasets, the final dataset has vars, E/M/H which each have valid values which need to be formatted differently. How would I format the E M H vars in this case?
Many thanks in advance!
%macro cont(input, var, byvar, odata,wgt,where, retain, num, nused);
*The BY var columns;
proc sort data=&input; by &byvar; run;
proc univariate data=&input noprint;
var &var;
weight &wgt;
&where
by &byvar;
output out=st_&odata._&byvar mean=Mean mode=Mode min=Minimum max=Maximum;
run;
proc transpose data=st_&odata._&byvar out=st_&odata._&byvar._tr;
id &byvar;
run;
data st_&odata._&byvar._tr;
retain _NAME_ &retain.;
set st_&odata._&byvar._tr;
if _NAME_="Mean" then num=&num.;
if _NAME_="Mode" then num=&num. +1;
if _NAME_="Minimum" then num=&num. +2;
if _NAME_="Maximum" then num=&num. +3;
if _NAME_ ne "_TYPE_";
drop _LABEL_;
run;
*The N column for checks;
proc freq data=&input;
table &var/missing out=n_&odata;
&where
run;
proc means data=n_&odata noprint;
var count;
output out=ntot_&odata sum=n;
run;
data ntot_&odata (keep= n);
set ntot_&odata;
run;
proc sort data=stat_&odata._&byvar._tr;
by num;
run;
data st_&odata._&byvar;
set st_&odata._&byvar._tr;
if _n_=1 then set ntot_&odata;
rename num=Col1;
run;
*All schools;
proc univariate data=&input noprint;
var &var;
weight &wgt;
output out=stall_&odata mean=Mean mode=Mode min=Minimum max=Maximum;
run;
proc transpose data=stall_&odata out=stall_&odata._tr;
run;
data stall_&odata._tr ;
set stall_&odata._tr;
if _NAME_="Mean" then num=&num.;
if _NAME_="Mode" then num=&num. +1;
if _NAME_="Minimum" then num=&num. +2;
if _NAME_="Maximum" then num=&num. +3;
if _NAME_ ne "_TYPE_";
rename col1=All;
rename num=Col1;
drop _LABEL_;
run;
proc sort data=stall_&odata._tr;
by Col1;
run;
proc sort data=st_&odata._&byvar;
by Col1;
run;
data cont_&byvar.&odata.;
length nused $50.;
retain col1 &retain n nused;
merge st_&odata._&byvar stall_&odata._tr;
by col1;
nused="&nused.";
proc print data= cont_&byvar.&odata.;
run;
%mend;
... View more