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

Hi All,

 

I am using SAS on demand for academics so I do not have access to ods output function.  

 

I have two proc report outputs from two data frames.  

 

the data frames are "test" and "test1"- 

 

data test;
input brand $ Freq Freq1 COUNT;
datalines;
A 2 3 8
B 3 5 4
C 4 6 2
D 5 1 1
E 6 5 8
F 7 7 9
;
run;

 


data test1;
input cars $ Freq Freq1 COUNT;
datalines;
g 4 1 9
h 6 0 5
i 8 1 6
j 1 6 8
k 7 4 4
l 6 5 1
;
run;

 

 

The two proc reports that I get from the above data frames are as below -

 

proc report data=test nowd out=abs
style(summary)=Header;
title 'test';
column brand
('Enrollment' Freq Freq1 COUNT);
define brand / group "Enrollment by Residency";
rbreak after / summarize;
run;

 


proc report data=test1 nowd out=abs
style(summary)=Header;
title 'test1';
column cars
('Enrollment' Freq Freq1 COUNT);
define cars / group "Enrollment by type";
rbreak after / summarize ;
run;

 

The output of these reports are attached as "Output" . However, my desired output has sub headings in between the observations as in the attachment "Desired output" 

 

Looking for some guidance on changing my "Output" to the "Desired output".  

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Where do Sub1 and Sub2 come from? It's not shown in your samples. For the code to be dynamic and account for that the logic has to flow from the data. 

 

data test;
infile cards truncover;
input GROUP_VAR $ brand $ Freq Freq1 COUNT;
datalines;      
SUB1 A 2 3 8
SUB1 B 3 5 4
SUB1 C 4 6 2
SUB2 D 5 1 1
SUB2 E 6 5 8
SUB2 F 7 7 9
;
run;

proc tabulate data=test;
class group_var brand / order=data missing;
var freq freq1 count;
table group_var=''*brand='', freq*sum='' freq1*sum='' count*sum=''/misstext='';
run;

proc report nowd data=test;
   col group_var brand freq freq1 count;
   define group_var / group noprint format=$8.;
   define brand/order;
   define freq/ sum;
   define freq1 / sum;
   define count / sum;
  break before group_var  / skip;
    compute before group_var/
      style={cellheight=8pt font_size=12pt just=left};
      line group_var $100.;
  endcomp;
run;

View solution in original post

7 REPLIES 7
HB
Barite | Level 11 HB
Barite | Level 11

It looks like you will need a "Compute After" but I'm not sure exactly how to implement that as i don't know how your car and brand groups are defined. 

 

https://communities.sas.com/t5/SAS-Procedures/How-to-Label-totals-and-subtotals-in-PROC-Report/td-p/...

 

Check page 5 of this PDF where they use a format statement to define the groups;

http://www.excursive.net/sas/ProcReportPaper.pdf

 

proc format;
value $Continent
'U.S.A.', 'CANADA'= 'NA'
'GERMANY' = 'EU';
run;

proc report data=smallprod
nowindows missing headline;
column country region predict actual;
define country / group format=$continent. width=7;
define region / group;
run;

prints:
Country Region PREDICT ACTUAL
-------------------------------------------
EU EAST 1,810.00 1,592.00
WEST 2,283.00 2,224.00
NA EAST 3,369.00 3,979.00
WEST 2,489.00 3,388.00

Probably need to do something like that for your brand/car groups and then use that format in "Define" and "Compute After".

 

Sorry, kind of lazy. marginally helpful response, but maybe it will be what you need.

75063
Obsidian | Level 7
Thank you for your reply. Here all the observations in cars and brand are independent to each other as they have been concatenated from various data sets. So we are unable to use a summary or grand total.
Reeza
Super User

I think you should consider combining your data and try PROC TABULATE instead. 

 


@75063 wrote:
Thank you for your reply. Here all the observations in cars and brand are independent to each other as they have been concatenated from various data sets. So we are unable to use a summary or grand total.

 

75063
Obsidian | Level 7
Thank you for your suggestion.
Can you guide me to a example of adding a subheading by Proc TABULATE. (Similar to the one I would like to get as output)
Reeza
Super User

Where do Sub1 and Sub2 come from? It's not shown in your samples. For the code to be dynamic and account for that the logic has to flow from the data. 

 

data test;
infile cards truncover;
input GROUP_VAR $ brand $ Freq Freq1 COUNT;
datalines;      
SUB1 A 2 3 8
SUB1 B 3 5 4
SUB1 C 4 6 2
SUB2 D 5 1 1
SUB2 E 6 5 8
SUB2 F 7 7 9
;
run;

proc tabulate data=test;
class group_var brand / order=data missing;
var freq freq1 count;
table group_var=''*brand='', freq*sum='' freq1*sum='' count*sum=''/misstext='';
run;

proc report nowd data=test;
   col group_var brand freq freq1 count;
   define group_var / group noprint format=$8.;
   define brand/order;
   define freq/ sum;
   define freq1 / sum;
   define count / sum;
  break before group_var  / skip;
    compute before group_var/
      style={cellheight=8pt font_size=12pt just=left};
      line group_var $100.;
  endcomp;
run;
Reeza
Super User

I am using SAS on demand for academics so I do not have access to ods output function.  

 

Are you sure about that? Is there some feature you tried that didn't work?

You have to specify the file paths correctly and you can download the files afterward but it works perfectly fine AFAIK. See the image below, I've XXXX out my name from the file path. 

 

delete_AoD.JPG

75063
Obsidian | Level 7
Thankyou for your reply. You are correct I can still have a ods output file if i specify the path correctly.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 7 replies
  • 1902 views
  • 1 like
  • 3 in conversation