I am working on a dataset that has 6 variables as treatment like A,B,C,D,E,F, and 6 categories Age, height, weight, BMI, Race, Gender as observations. Like below
A B C D E F
Age
Height
Weight
BMI
Race
Gender
I would like to use proc report where I need my first page and so forth as shown below. Basically having to break vertically trt variables and show three categories at a time. Any help will be highly appreciated.
A B C
Age
Height
Weight
D E F
Age
Height
Weight
A B C
BMI
Race
Gender
D E F
BMI
Race
Gender
Hi:
Although the posted solution will work for LISTING, it will NOT work for ODS HTML (or RTF or PDF). See the attached screenshot. It would be better to put the PAGE option on the DEFINE statement for variable D in order to indicate WHICH variable should start the page. As you can see, #1, uses the original code and does not work in HTML; however #2 code does work in HTML and LISTING and PDF and RTF. Note that options like HEADLINE, HEADSKIP and WIDTH= are LISTING only options and ignored by other ODS destinations.
Cynthia
data have;
input category $ A B C D E F;
cards;
Age 1 2 3 4 5 6
Height 1 2 3 4 5 6
Weight 1 2 3 4 5 6
BMI 1 2 3 4 5 6
Race 1 2 3 4 5 6
Gender 1 2 3 4 5 6
;
data have_;
set have;
if _n_ in (1,2,3) then flag=1;
else flag=2;
run;
ods _all_ close;
ods listing;
ods html file='c:\temp\forum_page.html';
ods rtf file='c:\temp\forum_page.rtf';
ods pdf file='c:\temp\forum_page.pdf';
proc report data= have_ missing;
title '1) Original solution works in LISTING but NOT in HTML, RTF or PDF';
column category a b c d e f flag;
define category / width=30 id;
define a / width=22 ;
define b / width=22 ;
define c / width=22 ;
define d / width=22 ;
define e / width=22 ;
define f / width=22 ;
define flag/ group noprint ;
break after flag/page ;
run;
proc report data= have_ missing;
title '2) Revised solution works in LISTING and HTML, (and RTF, PDF)';
column category a b c d e f flag;
define category / width=30 id;
define a / width=22 ;
define b / width=22 ;
define c / width=22 ;
define d / width=22 page;
define e / width=22 ;
define f / width=22 ;
define flag/ group noprint ;
break after flag/page ;
run;
ods _all_ close;
If you are just trying to get output as simply as possible, why not just have 4 separate PROC REPORTs . . .
Hi,
You can use the id option in the proc report, to achieve the desired result. The ID option will display the variables with id option in all the pages of the report.
In the define statement , we can use the id option for the respective variables you want to retain across all the pages.
Please try the sample code as below
data have;
input category$ A B C D E F;
cards;
Age 1 2 3 4 5 6
Height 1 2 3 4 5 6
Weight 1 2 3 4 5 6
BMI 1 2 3 4 5 6
Race 1 2 3 4 5 6
Gender 1 2 3 4 5 6
;
data have_;
set have;
if _n_ in (1,2,3) then flag=1;
else flag=2;
run;
proc report data= have_ headline headskip missing;
column category a b c d e f flag;
define category / width=30 id;
define a / width=22 ;
define b / width=22 ;
define c / width=22 ;
define d / width=22 ;
define e / width=22 ;
define f / width=22 ;
define flag/ group noprint ;
break after flag/page ;
run;
Thanks,
jag
Hi:
Although the posted solution will work for LISTING, it will NOT work for ODS HTML (or RTF or PDF). See the attached screenshot. It would be better to put the PAGE option on the DEFINE statement for variable D in order to indicate WHICH variable should start the page. As you can see, #1, uses the original code and does not work in HTML; however #2 code does work in HTML and LISTING and PDF and RTF. Note that options like HEADLINE, HEADSKIP and WIDTH= are LISTING only options and ignored by other ODS destinations.
Cynthia
data have;
input category $ A B C D E F;
cards;
Age 1 2 3 4 5 6
Height 1 2 3 4 5 6
Weight 1 2 3 4 5 6
BMI 1 2 3 4 5 6
Race 1 2 3 4 5 6
Gender 1 2 3 4 5 6
;
data have_;
set have;
if _n_ in (1,2,3) then flag=1;
else flag=2;
run;
ods _all_ close;
ods listing;
ods html file='c:\temp\forum_page.html';
ods rtf file='c:\temp\forum_page.rtf';
ods pdf file='c:\temp\forum_page.pdf';
proc report data= have_ missing;
title '1) Original solution works in LISTING but NOT in HTML, RTF or PDF';
column category a b c d e f flag;
define category / width=30 id;
define a / width=22 ;
define b / width=22 ;
define c / width=22 ;
define d / width=22 ;
define e / width=22 ;
define f / width=22 ;
define flag/ group noprint ;
break after flag/page ;
run;
proc report data= have_ missing;
title '2) Revised solution works in LISTING and HTML, (and RTF, PDF)';
column category a b c d e f flag;
define category / width=30 id;
define a / width=22 ;
define b / width=22 ;
define c / width=22 ;
define d / width=22 page;
define e / width=22 ;
define f / width=22 ;
define flag/ group noprint ;
break after flag/page ;
run;
ods _all_ close;
Hi Cynthia,
Thank you for showing the difference between the listing and the RTF, HTML, PDF. When i tested the code, i checked it only in the listing.
However here i would like to know why such difference is there between the listing and other ODS destination.
Regards,
Jag
Hi:
The LISTING destination (also known as the "monospace" destination, was originally, the ONLY destination. The LISTING destination is under the control of SAS for display and printing. Therefore, options like Linesize, Pagesize and other options, like HEADLINE, HEADSKIP in PROC REPORT were designed only for the LISTING destination. Other destinations are not impacted by options like Linesize and Pagesize. HTML, for example, does not even support page numbers. There aren't any HTML tags for page numbers.. That's because HTML is designed to be rendered in a browser. There are no page numbers in a browser. The LISTING destination does not use a proportional spaced font. In a fixed pitch font, like SAS Monospace or Courier, the letter 'i' takes up the same amount of space as the letter 'w'; while in a proportional spaced font, this is not true. Consider this:
Courier 10 pt:
iiiiiiiiiiiiiiiiiiii
wwwwwwwwwwwwwwwwwwww
Arial 10 pt:
iiiiiiiiiiiiiiiiiiii
wwwwwwwwwwwwwwwwwwww
This is the fundamental difference between LISTING and the other destinations. From this fundamental difference, all other differences follow. WIDTH=, for example in LISTING, absolutely determines the width of a cell in the output. So in PROC REPORT, you can have WIDTH=10 and the space allocated will be -exactly- 10 print positions in the LISTING output. However WIDTH=10 has no meaning in a proportion spaced font..what does WIDTH=10 mean -- 10 positions in the size of the letter 'w' or 10 positions the size of the letter 'i'? RTF is *NOT* the LISTING destination; PDF is *NOT* the LISTING destination; HTML is *NOT* the LISTING destination. You cannot expect these destinations to act like the LISTING destination. So, the way to change cell width, for example, for RTF, PDF and HTML is to use a STYLE= override and when you specify units of measure with ODS, you use pixels, inches or centimeters, NOT print positions.
I do not know the inner workings of PROC REPORT well enough to be able to comment on why the PAGE option works with ID statement the way it does for this example. The bottom line is that I never assume that just because something "works" in the LISTING destination, that it will work in other ODS destinations. I always test my code in LISTING and HTML or LISTING and all 3 of the major destinations.
cynthia
Thanks a ton Cynthia for a wonderful explanation.
I now understood clearly the difference between listing and other.
Regards,
Jag
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.