12-08-2011 10:08 AM
When I run a proc means and export the data there is an option to append a specific statistic to the new summary variable name (i.e. _MAX, _MIN, _SUM etc.).
for example if I was taking a Sum of Total_Sales my output would come out as TOTAL_SALES_SUM.
Is it possible to add another standard prefix or suffix to all my variables in the procedure?
so in this case I'd like to add ACTIVE_ to the variable name as a prefix so it would look like: ACTIVE_TOTAL_SALES_SUM
thanks for your help.
12-08-2011 11:18 AM
You can always use the rename option. e.g.:
PROC MEANS DATA=sashelp.class
VAR active_age active_height active_weight;
median = / AUTONAME;
A SAS support note shows a way to somewhat automate the task: http://support.sas.com/kb/34/568.html
12-08-2011 11:43 AM
Thanks for your reply Art.
I've been using the rename function but my dataset has ~200 variables that I would like to add the prefix too, so instead of writing it all out I was wondering if there is a quicker/easier way to append the prefix.
maybe a macro or some sort?
12-08-2011 12:28 PM
Did you look at the link I included in my last response? That is precisely what the note provides a method for accomplishing. http://support.sas.com/kb/34/568.html
12-13-2011 03:30 PM
I looked at the link you provided. I learn something from you everyday. Thank you!
/* get the list of variable names in the dataset */
proc contents data=sashelp.class out=stuff(keep=name type) noprint;
length sumname $30.;
/* create macro var with list of numeric variable names */
into utname separated by ' '
where type = 1;
into :inname separated by ' '
where type = 1;
proc means data=sashelp.class;
output out=mymeans(keep=active sum= &outname;
/* look at final output */
proc print data=&syslast; run;
12-08-2011 11:38 PM
You can always change it afterwards.
data temp; set sashelp.class; run; proc summary data=temp; var _numeric_; output out=have(drop=_type_ _freq_) sum= mean= /autoname; run; *Add prefix; data _null_; set sashelp.vcolumn(keep=libname memname name where=(libname='WORK' and memname='HAVE')) end=last; if _n_ eq 1 then call execute('proc datasets library=work nolist;modify have;rename '); call execute(cats(name,'=','Active_',name)); if last then call execute(';quit;'); run; *Add suffix; data _null_; set sashelp.vcolumn(keep=libname memname name where=(libname='WORK' and memname='HAVE')) end=last; if _n_ eq 1 then call execute('proc datasets library=work nolist;modify have;rename '); call execute(cats(name,'=',name,'_Active')); if last then call execute(';quit;'); run;