Hi
I am trying to display statistics with variable .Output is not showing var column.(var=age)what I am missing?
VAR is not a variable in your data set. It is a macro variable. Therefore, PROC MEANS cannot output it.
&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";
I need var='Age' for creating another dataset from this dataset.I tried adding var=&var in output statementt but its not working
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.
@paddyb wrote:
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.
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.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.