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
... View more