BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I have the following query in getting the below output.


Report Name

Lab Test: XXX
Unit: XXX

Subjid Age Sex Low Hight
1 65 M 11 112
13 234


I didn’t get how to print the ‘Lab Test: XXX’ . ‘XXX’ should be replaced by values of ‘lbtest’ from the dataset.
And we have more than one labtest with repeated values. I want to print the data of subjects for each lab test.
I got entire report except printing of ‘Lab Test: XXX’.
So please help me
2 REPLIES 2
Cynthia_sas
SAS Super FREQ
Hi:
You did not say what your report procedure of choice was or what your destination was. There are at least 3 different methods to do what you want. Without getting into the possibility of a custom table template or SAS Macro processing, the 3 methods below use PROC REPORT. However, the first method uses PROC REPORT and compute blocks and the second method uses PROC REPORT with a BY statement and TITLES to place that kind of identifying information above the table (in the Title); the third method uses PROC REPORT's COMPUTE BEFORE _PAGE_ capability to place the headers inside the boundary of the table area.

The second method will put every unique combination of Region and Subsidiary on a separate page -- which may or may not be what you want. In the first method, paging will depend on the destination -- which means that there are no "between group" page breaks. The third method will put every unique combination of Region and Subsidiary on a separate page, too. But in my example, the STARTPAGE=NO option will suppress the page breaks for RTF and PDF destinations.

cynthia
[pre]
*** the code;
ods listing close;
title;

proc sort data=sashelp.shoes out=shoes;
by region subsidiary;
where region in ('Asia', 'Canada', 'Pacific');
run;

** this method uses PROC REPORT compute blocks to place the headers;
** on the page based on their existence in the column statement;
** since they are NOPRINT variables, they can be used in the COMPUTE block;
ods rtf file='header_method1.rtf';
ods pdf file='header_method1.pdf';
ods html file='header_method1.html' style=sasweb;
proc report data=shoes nowd;
title '1) Custom Header Method1 -- with compute block';
column region subsidiary product sales returns inventory;
define region /group noprint;
define subsidiary /group noprint;
define product /order ;
define sales / sum ;
define returns/ sum;
define inventory /sum;
break after subsidiary/summarize;
compute before region;
holdreg = Region;
endcomp;
compute before subsidiary /
style={just=l};
holdsub = Subsidiary;
line 'Region: ' holdreg $25.;
line 'Subsidiary: ' holdsub $25.;
endcomp;
compute after subsidiary;
line ' ';
endcomp;
run;
ods _all_ close;

** this method generates a page for every "group" and uses the TITLE statement;
** to place the "header" information;
** If you use startpage=no for RTF and PDF with this method, you will only keep;
** the title for the first table on the page -- which may not be what you want;
ods rtf file='header_method2.rtf';
ods pdf file='header_method2.pdf';
ods html file='header_method2.html' style=sasweb;
options nobyline nocenter;
title j=l 'Region: #byval(region)';
title2 j=l 'Subsidiary: #byval(subsidiary)';
proc report data=shoes nowd;
by region subsidiary;
column region subsidiary product sales returns inventory;
define region /group noprint;
define subsidiary /group noprint;
define product /order ;
define sales / sum ;
define returns/ sum;
define inventory /sum;
break after subsidiary / summarize;
run;
ods _all_ close;

options byline center;
title;

** this method uses a variation of Method 1 but has some of the benefits of ;
** Method2 -- in that you can get every table on a page or not -- your choice.;
** It uses the page option on the BREAK statement and then a;
** COMPUTE before _PAGE_ to place the text above the columns;
** the startpage=no option for RTF and PDF places multiple tables on a page;
** if you want every table on a separate page, then delete the "startpage=no" option.;
ods rtf file='header_method3.rtf' startpage=no;
ods pdf file='header_method3.pdf' startpage=no;
ods html file='header_method3.html' style=sasweb;
proc report data=shoes nowd;
title '3) Custom Header Method3 -- with compute block before _page_';
column region subsidiary product sales returns inventory;
define region /group noprint;
define subsidiary /group noprint;
define product /order ;
define sales / sum ;
define returns/ sum;
define inventory /sum;
break after subsidiary/summarize page;
compute before region;
holdreg = Region;
endcomp;
compute before _page_ /
style={just=l font_weight=bold foreground=black};
holdsub = Subsidiary;
line 'Region: ' holdreg $25.;
line 'Subsidiary: ' holdsub $25.;
endcomp;
run;
ods _all_ close;
[/pre]
Olivier
Pyrite | Level 9
A simple way to include data-driven values into reports is to combine BY statements and #BYVALn references (that is, the current value of the n-th variable nammed in a BY statement) in Titles.
At least, it works out fine in HTML files ; some tricky things (bugs ?) may appear in Word or PDF files (I've experienced some trouble several times, but I am not currently able to re-generate them on demand).

Here is some example on SASHELP dataset.

ODS HTML FILE='c:\temp\header_method3.html' STYLE=SASWEB;
PROC SORT DATA = sashelp.class OUT = work.class ;
BY age sex name ;
RUN ;
PROC FORMAT ;
VALUE $sex "F" = "The girls are..." "M" = "The boys are..." ;
RUN ;
OPTION NOBYLINE ;
TITLE1 "List of children being #BYVAL1" ;
TITLE2 "#BYVAL2" ;
PROC PRINT DATA = work.class NOOBS LABEL ;
BY age sex ;
VAR name weight height ;
FORMAT sex $sex. ;
RUN ;
TITLE ;
ODS HTML CLOSE ;

Hope it helps.
Olivier

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