BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
PaigeMiller
Diamond | Level 26

Suppose I create a report using PROC REPORT

 

proc report data=sashelp.class; 
    columns age height weight;
	define age/group;
    define height/analysis mean format=10.2 "Height Mean";
    define weight/analysis mean format=10.1 "Weight Mean";
	rbreak after/summarize style=[font_style=italic];
run;

 

The report looks like this

 

PaigeMiller_0-1662481621394.png

 

 

but I want the bottom left cell (under Age, under 16) to have the text string 'All' inserted there. @Ksharp has shown me how to do this if AGE is a character variable. But in this case, AGE is numeric. I have tried creating a format such that a missing is replaced by 'All' and assigning that format to age. No success. I can't get it to work when AGE is a numeric variable. Can someone tell me how? Thanks!

--
Paige Miller
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Just do the exact same thing as for the character variable.

proc report data=sashelp.class; 
  columns age age2 height weight;
  define age/group noprint;
  define age2 / computed 'Age';
  define height/analysis mean format=10.2 "Height Mean";
  define weight/analysis mean format=10.1 "Weight Mean";
  compute age2 / character length=5 ;
    age2=put(age,5.);
  endcomp;
  compute after ;
    age2='Total';
  endcomp;
  rbreak after/summarize style=[font_style=italic];
run;

Tom_0-1662494470768.png

 

 

View solution in original post

6 REPLIES 6
ChrisHemedinger
Community Manager

I know you asked for REPORT and not TABULATE, but I can only figure out the answer for TABULATE.

proc tabulate
  data=sashelp.class

;
  var height weight;
  class age / order=unformatted missing;

  table /* row dimension */
    age 
      all={style={font_style=italic}}*{style={font_style=italic}},
      /* column dimension */
    height={label="Height (mean)"}*
      mean={label=""} 
      weight={label="Weight (mean)"}*
      mean={label=""};
    ;
run;

ChrisHemedinger_0-1662490866895.png

I'm sure a PROC REPORT expert will chime in with something different...

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
PaigeMiller
Diamond | Level 26

Thanks! I have a workaround where you run PROC SUMMARY to get the statistics, and then run PROC REPORT on the output of PROC SUMMARY, which honors the format on variable AGE. I know PROC SUMMARY well enough that I can get quick and correct answers with one hand tied behind my back. Also, I don't know PROC TABULATE. But, yes, a PROC REPORT answer would still be preferable.

--
Paige Miller
ChrisHemedinger
Community Manager

I also don't know TABULATE well...but the Summary Tables task in SAS Enterprise Guide with its drag-and-drop interaction generated the code I shared. I didn't do anything to it except make it not ALL CAPS 😉

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
Tom
Super User Tom
Super User

Just do the exact same thing as for the character variable.

proc report data=sashelp.class; 
  columns age age2 height weight;
  define age/group noprint;
  define age2 / computed 'Age';
  define height/analysis mean format=10.2 "Height Mean";
  define weight/analysis mean format=10.1 "Weight Mean";
  compute age2 / character length=5 ;
    age2=put(age,5.);
  endcomp;
  compute after ;
    age2='Total';
  endcomp;
  rbreak after/summarize style=[font_style=italic];
run;

Tom_0-1662494470768.png

 

 

FreelanceReinh
Jade | Level 19

Hello @PaigeMiller,

 

I've just found this solution/workaround accidentally while trying various options:

proc report data=sashelp.class; 
column age height weight;
define age/group mlf;
define height/analysis mean format=10.2 "Height Mean";
define weight/analysis mean format=10.1 "Weight Mean";
rbreak after/summarize style=[font_style=italic];
compute after;
  if _break_="_RBREAK_" then age="All";
endcomp;
run;

Then I remembered that @data_null__ mentioned the MLF trick earlier this year (not sure if it was this post).

 

Edit: Removed "format=3." as it was redundant.

PaigeMiller
Diamond | Level 26

Thanks @Tom and @FreelanceReinh . It seems like cheating to create a new column just to trick PROC REPORT into making the appearance of the output exactly what I want, but I have done it before. It seems like cheating to use the MLF option when you don't even have a multi-label format, but why not?

 

A slightly simpler version of the code from @FreelanceReinh 

 

proc report data=sashelp.class; 
column age height weight;
define age/group mlf;
define height/analysis mean format=10.2 "Height Mean";
define weight/analysis mean format=10.1 "Weight Mean";
rbreak after/summarize style=[font_style=italic];
compute after;
  age="All";
endcomp;
run;
--
Paige Miller

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1732 views
  • 8 likes
  • 4 in conversation