BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Phil_NZ
Barite | Level 11

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:

 

Phil_NZ_0-1618549465574.png

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.

Thank you for your help, have a fabulous and productive day! I am a novice today, but someday when I accumulate enough knowledge, I can help others in my capacity.
1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

6 REPLIES 6
yabwon
Onyx | Level 15

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Phil_NZ
Barite | Level 11

Hi @yabwon 

 

I run and it goes well, I am wondering why you say it is not elegant then?

Phil_NZ_0-1618565716835.png

Cheers,

 

Thank you for your help, have a fabulous and productive day! I am a novice today, but someday when I accumulate enough knowledge, I can help others in my capacity.
yabwon
Onyx | Level 15

Text is limited to 32 characters only 🙂 

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



yabwon
Onyx | Level 15

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Phil_NZ
Barite | Level 11

 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.

Thank you for your help, have a fabulous and productive day! I am a novice today, but someday when I accumulate enough knowledge, I can help others in my capacity.
yabwon
Onyx | Level 15

Try adding:

%put *%sysfunc(DLGCDIR(%sysfunc(pathname(WORK))))*;

before `ods html;` and let me know if it helped.

 

Bart

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

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
  • 6 replies
  • 855 views
  • 3 likes
  • 2 in conversation