Hi all SAS Users,
Today I use the PROC MEANS and label statement to make the report more aesthetic
ods noproctitle;
title 'Summary statistics align with previous papers';
footnote '16th, April,2021';
proc means data= merge_treat_con n nmiss mean median std min max;
var TOT_ASS wROA;
label TOT_ASS=Total Assets($)
wROA=Return on Assets
;
run;
title;footnote;
The result is as below:
What I want to focus on are two columns: Variable and Label. Now I want to delete the Column Variable and rename the column Label to Variable
Like this
Variable
Total Assets($)
Return on Assets
I know in other datastep we can use option or statement drop or rename but they seem not to work in proc mean.
Can you please help me to sort it out?
Thanks in advance.
Maybe this not elegant one with validvarname=ANY:
data merge_treat_con;
input TOT_ASS wROA;
cards;
1 2
3 4
5 6
7 8
;
run;
ods noproctitle;
OPTIONS VALIDVARNAME=ANY;
title 'Summary statistics align with previous papers';
footnote '16th, April,2021';
proc means data= merge_treat_con(rename=
(
TOT_ASS="Total Assets($)"n
wROA ="Return on Assets"n
)
) n nmiss mean median std min max;
var "Total Assets($)"n "Return on Assets"n;
run;
title;
footnote;
Bart
Maybe this not elegant one with validvarname=ANY:
data merge_treat_con;
input TOT_ASS wROA;
cards;
1 2
3 4
5 6
7 8
;
run;
ods noproctitle;
OPTIONS VALIDVARNAME=ANY;
title 'Summary statistics align with previous papers';
footnote '16th, April,2021';
proc means data= merge_treat_con(rename=
(
TOT_ASS="Total Assets($)"n
wROA ="Return on Assets"n
)
) n nmiss mean median std min max;
var "Total Assets($)"n "Return on Assets"n;
run;
title;
footnote;
Bart
Hi @yabwon
I run and it goes well, I am wondering why you say it is not elegant then?
Cheers,
Text is limited to 32 characters only 🙂
Bart
Other approach:
data merge_treat_con;
input TOT_ASS wROA;
cards;
1 2
3 4
5 6
7 8
;
run;
ODS HTML CLOSE;
ods noproctitle;
/*ods trace on;*/
ods output summary = stacked;
proc means data= merge_treat_con n nmiss mean median std min max
STACKODSOUTPUT;
var TOT_ASS wROA;
run;
/*ods trace off;*/
proc format;
value $ myLab
TOT_ASS="Total Assets($)"
wROA ="Return on Assets"
;
run;
ods html;
title 'Summary statistics align with previous papers';
footnote '16th, April,2021';
proc print data = stacked;
format variable $myLab.;
run;
title;
footnote;
Bart
Hi @yabwon
Thank you for your solution, when I run your code, the error happening as below, can you please help me to sort it out?
NOTE: Writing HTML Body file: sashtml33.htm
ERROR: Insufficient authorization to access C:\WINDOWS\system32\sashtml33.htm.
ERROR: No body file. HTML output will not be created.
The whole log
34 data merge_treat_conz;
35 input TOT_ASS wROA;
36 cards;
NOTE: The data set WORK.MERGE_TREAT_CONZ has 4 observations and 2 variables.
NOTE: Compressing data set WORK.MERGE_TREAT_CONZ decreased size by 0.00 percent.
Compressed is 1 pages; un-compressed would require 1 pages.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
41 ;
42 run;
43
44 ODS HTML CLOSE;
45
46 ods noproctitle;
47 /*ods trace on;*/
48 ods output summary = stacked;
49 proc means data= merge_treat_conz n nmiss mean median std min max
50 STACKODSOUTPUT;
51 var TOT_ASS wROA;
52 run;
NOTE: The data set WORK.STACKED has 2 observations and 8 variables.
NOTE: Compressing data set WORK.STACKED decreased size by 0.00 percent.
Compressed is 1 pages; un-compressed would require 1 pages.
NOTE: There were 4 observations read from the data set WORK.MERGE_TREAT_CONZ.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.02 seconds
cpu time 0.01 seconds
53 /*ods trace off;*/
54
55 proc format;
56 value $ myLab
57 TOT_ASS="Total Assets($)"
58 wROA ="Return on Assets"
59 ;
NOTE: Format $MYLAB is already on the library WORK.FORMATS.
NOTE: Format $MYLAB has been output.
60 run;
NOTE: PROCEDURE FORMAT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
61
62 ods html;
NOTE: Writing HTML Body file: sashtml33.htm
ERROR: Insufficient authorization to access C:\WINDOWS\system32\sashtml33.htm.
ERROR: No body file. HTML output will not be created.
2 The SAS System 19:20 Tuesday, April 13, 2021
63 title 'Summary statistics align with previous papers';
64 footnote '16th, April,2021';
65 proc print data = stacked;
66 format variable $myLab.;
67 run;
NOTE: Access by observation number not available. Observation numbers will be counted by PROC PRINT.
NOTE: There were 2 observations read from the data set WORK.STACKED.
Warm regards.
Try adding:
%put *%sysfunc(DLGCDIR(%sysfunc(pathname(WORK))))*;
before `ods html;` and let me know if it helped.
Bart
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.