BYGROUP 1: Table 1 Table 2 Table n BYGROUP 2: Table 1 Table 2 Table n
It is often the case that the desired order is:
BYGROUP1: Table 1 BYGROUP2: Table 1 BYGROUP1: Table 2 BYGROUP2: Table 2
Using SAS macro logic, the desired order can be achieved, but requires multiple procedure steps to accomplish the desired output. With the use of ODS DOCUMENT and PROC DOCUMENT, output from one or more SAS procedures (PROC FREQ in the sample code) can be stored to a DOCUMENT itemstore, then with PROC DOCUMENT, the output can be replayed in the desired order without repeating the initial procedure (FREQ) step.
Additional information on the ODS DOCUMENT destination and PROC DOCUMENT is available
here.
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
/* Create a data set from SASHELP.CLASS */
data mydata;
set sashelp.class;
rename sex=gender;
run;
/* SORT the data set */
proc sort data=mydata out=sorted;
by gender;
run;
options orientation=landscape center nodate nonumber byline;
title ;
footnote;
/* Create a DOCUMENT in the SASUSER library */
ods document name=sasuser.freq(update);
/* show the output in a PDF file in it's original order */
/* the default order is:
BYGROUP 1: Table 1, Table 2, Table 3, Table 4
BYGROUP 2: Table 1, Table 2, Table 3, Table 4
*/
ods pdf file="original.pdf" notoc;
ods noptitle;
proc freq data=sorted;
where height le 60;
format height weight 8.;
by gender;
tables (height weight)*age / chisq;
run;
ods pdf close;
ods document close;
/* Show the details of the DOCUMENT */
ods listing;
title "what's in my DOCUMENT?";
proc document name=sasuser.freq;
list / levels=all;
run;
quit;
title ;
footnote;
/* Replay the PROC FREQ output in a new order: */
/*
BYGROUP 1: Table 1
BYGROUP 2: Table 1
BYGROUP 1: Table 2
BYGROUP 2: Table 2
BYGROUP 1: Table 3
BYGROUP 2: Table 3
BYGROUP 1: Table 4
BYGROUP 2: Table 4
*/
ods listing close;
ods pdf file="&sysvlong.replay.pdf" columns=2 notoc;
proc document name=sasuser.freq;
replay \Freq#1\ByGroup1#1\Table1#1\CrossTabFreqs#1;
replay \Freq#1\ByGroup2#1\Table1#1\CrossTabFreqs#1;
run;
obstitle \Freq#1\ByGroup1#1\Table1#1\Note#2 ;
replay \Freq#1\ByGroup1#1\Table1#1\ChiSq#1,
\Freq#1\ByGroup1#1\Table1#1\Note#2;
obstitle \Freq#1\ByGroup2#1\Table1#1\Note#2 ;
replay \Freq#1\ByGroup2#1\Table1#1\ChiSq#1,
\Freq#1\ByGroup2#1\Table1#1\Note#2;
run;
replay \Freq#1\ByGroup1#1\Table2#1\CrossTabFreqs#1;
replay \Freq#1\ByGroup2#1\Table2#1\CrossTabFreqs#1;
run;
obstitle \Freq#1\ByGroup1#1\Table2#1\Note#2 ;
replay \Freq#1\ByGroup1#1\Table2#1\ChiSq#1,
\Freq#1\ByGroup1#1\Table2#1\Note#2;
obstitle \Freq#1\ByGroup2#1\Table2#1\Note#2 ;
replay \Freq#1\ByGroup2#1\Table2#1\ChiSq#1,
\Freq#1\ByGroup2#1\Table2#1\Note#2;
run;
quit;
ods pdf close;
/* delete the document if desired */
/*ods listing ;*/
/*proc datasets lib=sasuser mt=itemstor;*/
/*delete freq;*/
/*run;*/
/*quit;*/
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
Type: | Sample |
Date Modified: | 2009-02-27 16:33:19 |
Date Created: | 2009-01-28 16:30:49 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | Base SAS | z/OS | 9.1 TS1M3 | |
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.1 TS1M3 | |||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.1 TS1M3 | |||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.1 TS1M3 | |||
Microsoft Windows XP 64-bit Edition | 9.1 TS1M3 | |||
Microsoft® Windows® for x64 | 9.1 TS1M3 | |||
Microsoft Windows 2000 Advanced Server | 9.1 TS1M3 | |||
Microsoft Windows 2000 Datacenter Server | 9.1 TS1M3 | |||
Microsoft Windows 2000 Server | 9.1 TS1M3 | |||
Microsoft Windows 2000 Professional | 9.1 TS1M3 | |||
Microsoft Windows NT Workstation | 9.1 TS1M3 | |||
Microsoft Windows Server 2003 Datacenter Edition | 9.1 TS1M3 | |||
Microsoft Windows Server 2003 Enterprise Edition | 9.1 TS1M3 | |||
Microsoft Windows Server 2003 Standard Edition | 9.1 TS1M3 | |||
Microsoft Windows XP Professional | 9.1 TS1M3 | |||
Windows Vista | 9.1 TS1M3 | |||
64-bit Enabled AIX | 9.1 TS1M3 | |||
64-bit Enabled HP-UX | 9.1 TS1M3 | |||
64-bit Enabled Solaris | 9.1 TS1M3 | |||
HP-UX IPF | 9.1 TS1M3 | |||
Linux | 9.1 TS1M3 | |||
OpenVMS Alpha | 9.1 TS1M3 | |||
Tru64 UNIX | 9.1 TS1M3 |