BookmarkSubscribeRSS Feed
deleted_user
Not applicable
hi friends,

i have a means procedure for which i have edited its template .
i have just removed the varname column and edited header names of few other columns.
but i have one problem for which i am not able to find solution . may be some one could help me.
my proc means is in a macro do loop ,
and the var statement in my proc means is also dynamic ,
so when the var statment has more than one analysis variable , they get listed in my label column of output,
but when i have only one analysis variable no label column is generated ,
i have removed the header so header also don't get generated.

i want that variable in the label column of the output so report format will remain same. so how can i do that ?

Thanks
regards
Avi
11 REPLIES 11
Andre
Obsidian | Level 7
Avi,
You know that this kind of code is complex
so try please to forward some names of the existing template you have rewritten
and some code extract pending with your problem
TIA
Andre
deleted_user
Not applicable
ok Andre

this is not my orignal code as its too big and complex.
but this code will let you know my problem.

the template is
------------------------------------------------------------------------------------------------------------
libname CUSTOM1 'd:\Sas data\sas user data\sas\projects';
ods path SASUSER.TEMPLAT(UPDATE) SASHELP.TMPLMST(READ);
proc template ;
define table Base.Summary / store=CUSTOM1.TEMPLAT(UPDATE);
PRINT_HEADERS = OFF;
column class (label)(MEAN) (Stddev)
(MIN )(MAX ) (N) (P1) (P10)(Q1) (MEDIAN)(Q3)(P90) (P99);
define max;
define header hmax;
text2 "Max";
text "Max";
end;
header = hmax;
generic;
end;
define min;
define header hmin;
text2 "Min";
text "Min";
end;
header = hmin;
generic;
end;
define label;
header = "Observation Point ";
id;
generic;
end;
define p10;
header = "10th Pctl";
generic;
end;

define p1;
header = "1st Pctl";
generic;
end;
define p99;
header = "99th Pctl";
generic;
end;

define p90;
header = "90th Pctl";
generic;
end;

define q3;
header = "Upper Qrtl";
generic;
end;
define q1;
header = "Lower Qrtl";
generic;
end;

define median;
header = "Median";
generic;
end;

define stddev;
header = "Std Dev";
generic;
end;

define mean;
header = "Mean";
generic;
end;
define n;
header = "Count";
generic;
end;
define class;
vjust = T;
id;
generic;
blank_internal_dups;
end;
end;
run;

-------------------------------------------------------------------------------------
ods path CUSTOM1.TEMPLAT(UPDATE) SASUSER.TEMPLAT(UPDATE) SASHELP.TMPLMST(READ);

%macro genrpt;
ods pdf file="xyz.pdf";
%do i=1 %to 5;
proc sql noprint;
select distinct(cols) into :mvar seperated by ' ' from table1 one where flag="&i";
quit;
proc means data= table2 ;
var &mvar;
class odtype;
run;
%end;
ods pdf close;
%mend;

%genrpt;
.. this might give you glimps.
the var statement in means in dynamic....

regards
Avi
Cynthia_sas
SAS Super FREQ
Hi:
It could be as simple as having a LABEL statement in your PROC MEANS. I don't think the macro code has anything to do with what's wrong. Since you've disappeared the (varname) from the COLUMN definition in the Base.Summary table template, you are telling MEANS to only show the LABEL. But, that means if there's no label, you will NOT get a column.

For example, I tested your template with SASHELP.CLASS (which does not have labels for AGE, HEIGHT or WEIGHT) and I do NOT get your "Observation Point" column in the output.

However, if I put a LABEL statement in the PROC MEANS, then, using your altered template, I DO get the "Observation Point" column in the output. If the code works outside of the macro environment, there is nothing in your macro code that alters the template. You might consider putting (VARNAME) back in the COLUMN statement or consider using a LABEL statement inside PROC MEANS.


cynthia

[pre]
ods path work.TEMPLAT(UPDATE) SASUSER.TEMPLAT(UPDATE) SASHELP.TMPLMST(READ);
** create altered Base.Summary template;

** no Observation Point column because NO labels for age, height and weight;
ods pdf file="c:\temp\nolabel.pdf";
proc means data= sashelp.class;
var age height weight;
class sex;
run;
ods pdf close;

** DO get Observation Point column;
ods pdf file="c:\temp\getlabel.pdf";
proc means data= sashelp.class;
var age height weight;
class sex;
label age='Age'
height = 'Height'
Weight = 'Weight';
run;
ods pdf close;
[/pre]
deleted_user
Not applicable
Hi Cynthia,
I have the labels for every column.
the problem is when in var statement if there is only one analysis variable it does not show that observation point column.



thanks and regards
Avi
Cynthia_sas
SAS Super FREQ
Hi:
But the REGULAR behavior of PROC MEANS is to show you ONE analysis variable in the header. Then if you have two or more analysis variables, you get them listed beside the CLASS variables. I'm not sure you can change -that- behavior.

For example, if I do this (using the DEFAULT Base.Summary):
[pre]
ods path SASHELP.TMPLMST(READ);

ods pdf file="c:\temp\default1.pdf";
proc means data= sashelp.class;
var age;
class sex;
label age='Age';
run;
ods pdf close;

ods pdf file="c:\temp\default2.pdf";
proc means data= sashelp.class;
var age weight;
class sex;
label age='Age' weight='Weight';
run;
ods pdf close;

[/pre]

Then I do NOT get the AGE displayed next to the CLASS variable for the one variable situation; but I do get the names/labels displayed next to the CLASS variable for the two variable situation.

I don't think you can change this default behavior with your table template. That would be a question for Tech Support. OR, you could try PROC TABULATE instead of PROC MEANS:
[pre]

proc tabulate data=sashelp.class;
var age weight;
class sex;
table sex=' ' *(age weight),
n mean stddev min max /row=float box=sex;
run;

[/pre]

cynthia
deleted_user
Not applicable
ok,
why this behaviour cannot be changed through table template.
does it deal with dynamic statement which i have not written in template. as it as a column name one_var one_var_name .....

my proc means is in a macro to which many analysis variable may come or one analysis variable may come...


can proc tabulate satisfy this?

regards
Avi..
Cynthia_sas
SAS Super FREQ
Hi:
But, the DYNAMIC statement is in effect when you use the DEFAULT template without making any changes and you still do NOT get the name/label of the analysis variable listed beside the CLASS var. That behavior ONLY happens, by default, when you have 2 or more analysis variables.

So, the DYNAMIC statement is not at fault. even if you add a DYNAMIC statement back into your template, with ONE variable, PROC MEANS uses the default behavior.

Depending on what you want, PROC TABULATE can use a variable list for the VAR statement, same as PROC MEANS. Here's a little test. I didn't bother with a %DO loop.

cynthia

[pre]
%macro dotab(clvar=, varlist=);
proc tabulate data=sashelp.class;
var &varlist;
class &clvar;
table &clvar=' ' *(&varlist),
n mean stddev min max /row=float box=&clvar;
run;
%mend dotab;

ods pdf file='c:\temp\testmac.pdf' ;
title "One Analysis Var";
%dotab(clvar=sex, varlist=age);
run;

title "Two Analysis Vars";
%dotab(clvar=sex, varlist=age weight);
run;

title "Three Analysis Vars";
%dotab(clvar=sex, varlist= age height weight);
run;
ods pdf close;
[/pre]
deleted_user
Not applicable
Thanks Cynthia.

I did used proc tabulate
but as i used "observation point " as header for the analysis variable/s column.
proc tabulate does not give me same o/p.
for remaining stats .it was easy to change headers .

also the for each class type , the whole box row contains horizontal lines for every analysis variable (even though i used NOSEPS) which is using my space.

over all it does not give look and feel which proc means gave.

regards
Avi
Cynthia_sas
SAS Super FREQ
Hi:
You could try to put
box='Observation Point' in your tabulate to see whether that's what you want.

NOSEPS is only honored in the LISTING destination. For all other ODS destinations, you would have to use different methods to remove or alter the interior table lines. (STYLE= overrides)

You're right, it does not have the same look and feel as PROC MEANS. However, you only need to compromise on the look for the situations where you have only 1 variable for analysis.

You could use proc tabulate for your one analysis var situation and use proc means when you know you have two or more analysis vars. In that instance, you don't have to worry about the interior table lines on a one var situation. And using a different proc for one condition versus another proc for more than one analysis variable is not too difficult a macro task.

cynthia
[pre]
%macro dotab(clvar=, varlist=);

%let numvar = %sysfunc(countw(&varlist));
%put numvar= &numvar;

%if &numvar = 1 %then %do;
proc tabulate data=sashelp.class;
var &varlist / style=Data;
class &clvar;
classlev &clvar / style=Data;
table &clvar=' ' *(&varlist),
mean stddev min max n
/row=float box={label='Observation Point' style={just=c}};
keylabel n='Count'
stddev = 'Std Dev';
run;
%end;
%else %if &numvar gt 1 %then %do;
proc means data= sashelp.class nway;
var &varlist;
class &clvar;
label age='Age' height='Height' weight='Weight';
run;
%end;
%mend dotab;

ods path work.TEMPLAT(UPDATE) SASUSER.TEMPLAT(UPDATE) SASHELP.TMPLMST(READ);

ods pdf file='c:\temp\testmac_alt.pdf' ;
title "One Analysis Var";
%dotab(clvar=sex, varlist=age);
run;

title "Two Analysis Vars";
%dotab(clvar=sex, varlist=age weight);
run;

title "Three Analysis Vars";
%dotab(clvar=sex, varlist= age height weight);
run;
ods pdf close;
[/pre]
Cynthia_sas
SAS Super FREQ
Hi:
I'm thinking that PROC REPORT may be more to your taste for the one variable situatioin instead of TABULATE.

cynthia
[pre]
%macro dotab(clvar=, varlist=);

%let numvar = %sysfunc(countw(&varlist));
%put numvar= &numvar;

%if &numvar = 1 %then %do;

proc report data=sashelp.class nowd;
title 'PROC REPORT One Var';
column &clvar col2 &varlist,(mean std min max n);
define &clvar / group ' ';
define col2/ computed 'Observation Point'
style(header)={just=l};
define &varlist/ ' ';
define mean / 'Mean';
define std / 'Std Dev';
define min / 'Min' f=comma15.7;
define max / 'Max' f=comma15.7;
define n / 'Count';
compute col2 / character length=20;
col2 = propcase("&varlist");
endcomp;
run;


%end;
%else %if &numvar gt 1 %then %do;
ods noptitle;
title "Proc Means for &numvar Analysis Variables";
proc means data= sashelp.class nway;
var &varlist;
class &clvar;
label age='Age' height='Height' weight='Weight';
run;
%end;
%mend dotab;

ods path work.TEMPLAT(UPDATE) SASUSER.TEMPLAT(UPDATE) SASHELP.TMPLMST(READ);

ods pdf file='c:\temp\testmac_alt_rept.pdf' ;
%dotab(clvar=sex, varlist=age);
run;

%dotab(clvar=sex, varlist=age weight);
run;

%dotab(clvar=sex, varlist= age height weight);
run;
ods pdf close;
[/pre]
deleted_user
Not applicable
great Cynthia .. Thanks for the Support.

Surely Proc report is much more easy & better solution.
and also %if macro came for rescue. 🙂 .

Regards
Avi.

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 1562 views
  • 0 likes
  • 3 in conversation