DATA Step, Macro, Functions and more

proc means result need to show analysis variable

Reply
Contributor
Posts: 54

proc means result need to show analysis variable

[ Edited ]

Hi

 

I am trying to display  statistics with variable .Output is not showing var column.(var=age)what I am missing?

Respected Advisor
Posts: 2,825

Re: proc means result need to show analysis variable

VAR is not a variable in your data set. It is a macro variable. Therefore, PROC MEANS cannot output it. 

 

 

--
Paige Miller
Trusted Advisor
Posts: 1,831

Re: proc means result need to show analysis variable

&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";

 

Contributor
Posts: 54

Re: proc means result need to show analysis variable

I need var='Age' for creating another dataset from this dataset.I tried adding var=&var in output statementt but its not working

Respected Advisor
Posts: 2,825

Re: proc means result need to show analysis variable

[ Edited ]

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. 

--
Paige Miller
Contributor
Posts: 54

Re: proc means result need to show analysis variable

Posted in reply to PaigeMiller
Thank you.Actually I am calculating proc means for 6 variables so used macro.
Respected Advisor
Posts: 2,825

Re: proc means result need to show analysis variable


@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. 

--
Paige Miller
Super User
Posts: 23,293

Re: proc means result need to show analysis variable

[ Edited ]

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.	
 
 
Ask a Question
Discussion stats
  • 7 replies
  • 133 views
  • 1 like
  • 4 in conversation