BookmarkSubscribeRSS Feed
mhouse
Fluorite | Level 6

Hello,

 

I'm in EG trying to create a report that splits the output into different tables by my variable APPLICATION. The code I have is below... I want it to output new tables by application but on the same page and without the title printed on every page. Currently, a page break is inserted between each new table and the titles are written on each page. I got this to work with proc print easily with the same by variable but it doesn't behave the same way in proc report. I am using proc report so I can do conditional style formatting.

 

proc report data = items;
by application;

compute item;
if item = '*not available*' then 
	call define(_row_,'style','style={foreground=orange font_weight=bold}');
endcomp;

label 	item= "Items"
		application = "Application"
		var3 = "Var 3"
		var4 = "Var 4";

title1 	"List of Items";
title2 	"last updated%sysfunc(date(),worddate.)";
title3 	" ";

run;
3 REPLIES 3
Cynthia_sas
SAS Super FREQ
Hi:
You do not show ALL your code or mention the destination of interest. Where is your COLUMN statement? Where are your DEFINE statements? PROC PRINT and PROC REPORT do act differently with BY group processing, but some destinations give you a way to suppress the titles between outputs and some don't. Can you clarify your destination of interest (HTML, RTF, PDF, etc) and show ALL of your code. If you can't provide data, then you might consider writing a similar program using a dataset like SASHELP.SHOES.

cynthia
mhouse
Fluorite | Level 6

Hi @Cynthia_sas,

 

Sorry, I am a beginner and doing my best to learn...

 

My code seems to parse and output with and without the DEFINE and COLUMN statements so I didn't see a need to include them. I don't know what the output destination is yet. I'd like to just have the view corrected in the results and then be able to export to whatever format I need after - is that an option? In terms of sashelp.shoes, I can give you this code (but now the conditional style formatting doesn't work though it works on my code and data):

 

data lookAround;
set sashelp.shoes;
proc sort;
by product;
run;

proc report data = lookAround;
/*column region product stores sales ;*/
/*by product;*/

/*define sales / missing;*/
compute sales;
if sales < 10000 then 
	call define(_row_,'style','style={foreground=orange font_weight=bold}');
endcomp;

label 	region = "Region"
		product = "Product"
		stores = "Stores"
		sales = "Sales";

title1 	"sashelp Shoes";
title2 	"last updated%sysfunc(date(),worddate.)";
title3 	" ";

run;

 

Thanks!

Cynthia_sas
SAS Super FREQ

Hi,

  Just because code works without some statements doesn't mean that you don't need them. If you do not use a DEFINE statement, then you are allowing PROC REPORT to set all the defaults. For example, the SALES variable could be used in the default mode, which would be as an analysis item. If you take the default, then you need to use the "compound" name of SALES.SUM in your COMPUTE block. If, on the other hand, you DO have DEFINE statement with a specific usage of DISPLAY, then you can use the simple reference to SALES in the COMPUTE block.

  If you do NOT know about ODS -- the Output Delivery System is how you will accomplish your goal to " then be able to export to whatever format I need". For example, I have modified your code a bit to show you how to create RTF, PDF and HTML results from PROC REPORT automatically. Note the ODS statements at the top and the bottom of the code. These cause SAS to use ODS to direct the report output from 1 run of PROC REPORT to 3 different output formats automatically. The FILE= option shows you the name of the file where the output is written and then the screen shots show how the BY statement was used by each destination.


Here's the code:

 

** limit the rows to make it easier to review the page breaks;

proc sort data=sashelp.shoes out=lookaround;
by product region;
where region in ('Asia','Africa', 'Canada') and
      product contains 'Casual';
run;

 

** Test1: use ODS destinations to send output to different files. ;    

ods pdf file='c:\temp\test1.pdf' startpage=no;
ods rtf file='c:\temp\test1.rtf' startpage=no;
ods html file='c:\temp\test1.html';
proc report data = lookAround;
  title '1) Method 1 of referring to SALES';
 column region product sales inventory returns ;
 by product ;

 define sales / analysis 'Sales';
compute sales;
if sales.sum < 20000 then
 call define(_row_,'style','style={foreground=orange font_weight=bold}');
endcomp;

label  region = "Region"
  product = "Product";

title2  "sashelp Shoes";
title3  "last updated%sysfunc(date(),worddate.)";
title4  " ";

run;
ods _all_ close;

 

** Test 2: define SALES as DISPLAY changes COMPUTE BLOCK reference;

ods pdf file='c:\temp\test2.pdf' startpage=no;
ods rtf file='c:\temp\test2.rtf' startpage=no;
ods html file='c:\temp\test2.html';
proc report data = lookAround;
  title '2) Method 2 of referring to SALES';
 column region product  sales inventory returns;
 by product ;

 define sales / display;
compute sales;
if sales < 20000 then
 call define(_row_,'style','style={foreground=orange font_weight=bold}');
endcomp;

label  region = "Region"
  product = "Product";

title2  "sashelp Shoes";
title3 "last updated%sysfunc(date(),worddate.)";
title4  " ";

run;
ods _all_ close;

 

** Test 3: change usage of REGION to GROUP to see difference in output; 
ods pdf file='c:\temp\test3.pdf' startpage=no;
ods rtf file='c:\temp\test3.rtf' startpage=no;
ods html file='c:\temp\test3.html';
proc report data = lookAround;
  title '3) Changing usage of region to group instead of taking the default DISPLAY usage';
  title2 'notice how report becomes a summary report without PRODUCT on the report';
 column region  sales inventory returns;
 by product ;
 define region / group 'Region';;
 define sales / sum 'Sales';
compute sales;
if sales.sum < 20000 then
 call define(_row_,'style','style={foreground=orange font_weight=bold}');
endcomp;

title3  "sashelp Shoes";
title4  "last updated%sysfunc(date(),worddate.)";
title5  " ";
 
run;
ods _all_ close;
 
 
What you should see if you run the code is that the #1 report and the #2 report look the same, (but using 2 different references in the COMPUTE block) but the #3 report will look markedly different with the usage of REGION set to GROUP instead of taking the default of DISPLAY. In addition, you should also see that the BYLINE information and the TITLE information are handled different in the HTML file than in the other outputs.
  
cynthia

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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