04-08-2018 06:53 PM
&var is a constant value = "age". I see no sense of adding a column with a constant value.
you can add TITLE to the proc means as:
title "Analysis for &var";
04-08-2018 07:29 PM - edited 04-08-2018 07:30 PM
If I understand you properly, and I may not be understanding you properly, this should work.
Data stat_&var; set stat_&var; var="&var" ; run;
I also get the impression that macros are not needed here, but without seeing the larger picture, I can't know for sure. I get the impression you working hard to get a macro solution when something simpler would work.
In the future, please include your SAS code directly in your message (and not as an attachment) by clicking on the "running man" icon and then typing or pasting your code into that window.
04-08-2018 07:52 PM
Thank you.Actually I am calculating proc means for 6 variables so used macro.
In PROC MEANS, put all six variables into the VAR statement.
04-08-2018 07:42 PM - edited 04-08-2018 07:56 PM
The method you're using, PROC MEANS + TRANSPOSE is a bit outdated. I prefer using the ODS OUTPUT which includes the variables and statistics in the form you're probably trying to achieve .
proc means data=sashelp.cars stackods n mean min max median nway; class origin make; var mpg_highway mpg_city length; ods output summary=want; run;
Look at the output here, in the WANT table. You can see there's a variable called VARIABLE that has the variable name, and the output by default is already in the format you want. If there's a statistic you want that's not listed, include it in the PROC MEANS statement.
EDIT: changed example to show it works with multiple variables.
%macro contstats(ds=,var=); proc means data = &ds. completetypes nway chartype missing noprint ; class trt02p/missing mlf; var &var; output out = stats&var (drop=_type_ _freq_) n=n mean=Mean stddev=SD median=Median min=Min max=Max ; run; proc transpose data = stats&var out = stat_&var (drop=_label_); id trt02p; run; %mend contstats; %contstats(ds=adsl_,var=age); output I got is trt02p ,n , mean , sd ,median , min , max 10 mg 5 31.9 15.39 24.3 18.6 56 20 mg 5 23.68 6.496 21.9 18.4 34.2 40 mg 5 22.16 3.502 21.5 18.3 27.1 80 mg 4 25.325 3.831 24.4 22 30.5 output I want is column var with value age before trt02p.