Hi there
I have a dataset containing a list of the participants of a research study (participant id, participant demographics, indicator of treatment group or control group). I am producing a report for each participant.
I would like to write a line of text (I am thinking of using ods pdf text), but only if the participant is in the treatment group.
Thanks in advance for the help
Depends a bit how the rest of your process is set up but a macro %IF/%THEN is one option.
The logic will be similar to this but simplified.
Proc report with different titles, fornotes and Pag 1 of <n>
ODS PDF. Write a line of text if condition is satisfied
I believe the solution below will also work for the pdf destination.
this message
https://goo.gl/ZZLhTv
https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-PDF-Write-a-line-of-text-if-condition-is-satisfied/m-p/348526
see for output
https://www.dropbox.com/s/z60z04j8rzplfbn/difTytFot.rtf?dl=0
This is a dumb example that can be done with a macro however
the meta data could involve dozens of rows.
You can convert this to amacro quite easily.
HAVE ( Meta data and sashelp.class )
=====================================
Up to 40 obs WORK.META total obs=2
PAT1 TYT1 FOT1
M Invoice 2378675 for Rural Participants see Protocol 1013.6(Oncology)
F Invoice 288675 for Urban Participants see Protocol 10883.6(Analgesics)
Up to 40 obs from sashelp.class total obs=19
Obs NAME SEX AGE HEIGHT WEIGHT
1 Alfred M 14 69.0 112.5
2 Alice F 13 56.5 84.0
3 Barbara F 13 65.3 98.0
4 Carol F 14 62.8 102.5
5 Henry M 14 63.5 102.5
6 James M 12 57.3 83.0
...
WANT (two page report with different title and footnotes)
==========================================================
PAGE 1
Student Clinical Trial Males
Invoice 2378675 for Rural Participants
NAME SEX AGE HEIGHT WEIGHT
Alfred M 14 69 112.5
Henry M 14 63.5 102.5
James M 12 57.3 83
Jeffrey M 13 62.5 84
John M 12 59 99.5
Philip M 16 72 150
Robert M 12 64.8 128
Ronald M 15 67 133
Thomas M 11 57.5 85
William M 15 66.5 112
Page 1 of 2
Program: c:/utl/dm.sas_09APR17
Log: c:/utl/dm.log_09APR17
see Protocol 1013.6(Oncology)
PAGE 2
Student Clinical Trial Females
Invoice 288675 for Urban Participants
NAME SEX AGE HEIGHT WEIGHT
Alice F 13 56.5 84
Barbara F 13 65.3 98
Carol F 14 62.8 102.5
Jane F 12 59.8 84.5
Janet F 15 62.5 112.5
Joyce F 11 51.3 50.5
Judy F 14 64.3 90
Louise F 12 56.3 77
Mary F 15 66.5 112
Page 2 of 2
Program: c:/utl/dm.sas_09APR17
Log: c:/utl/dm.log_09APR17
see Protocol 10883.6(Analgesics)
WORKING CODE
============
array pat[&sqlobs] $8 (&pat.);
array tyt[&sqlobs] $64 (&tyt.);
array fot[&sqlobs] $64 (&fot.);
do i=1 to &sqlobs;
rc=dosubl(
FULL SOLUTION
=============
* _ _ _
_ __ ___ __ _| | _____ __| | __ _| |_ __ _
| '_ ` _ \ / _` | |/ / _ \_____ / _` |/ _` | __/ _` |
| | | | | | (_| | < __/_____| (_| | (_| | || (_| |
|_| |_| |_|\__,_|_|\_\___| \__,_|\__,_|\__\__,_|
;
%utl_rtflan100;
%let pgm=utl_diff_tyt_rtf;
%let outfile=d:/rtf/difTytFot.rtf;
%utl_rtflan100;
data meta;
pge1='1';
pat1='M';
tyt1='Invoice 2378675 for Rural Partipicpants ';
fot1='see Protocol 1013.6(Oncology) ';
output;
pge1='2';
pat1='F';
tyt1='Invoice 288675 for Urban Partipicpants ';
fot1='see Protocol 10883.6(Analgesics) ';
output;
run;quit;
options nodate nonumber orientation=portrait;
title;footnote;
ods escapechar='^';
ods listing close;
ods rtf file="&outfile" style=utl_rtflan100 notoc_data;
* _ _ _
___ ___ | |_ _| |_(_) ___ _ __
/ __|/ _ \| | | | | __| |/ _ \| '_ \
\__ \ (_) | | |_| | |_| | (_) | | | |
|___/\___/|_|\__,_|\__|_|\___/|_| |_|
;
%symdel pge pat tyt fot/ nowarn;
data _null_;
* get meta data;
if _n_=0 then do;
rc=%sysfunc(dosubl('
proc sql noprint ;
select
quote(pat1)
,quote(tyt1)
,quote(fot1)
into
:pat separated by ","
,:tyt separated by ","
,:fot separated by ","
from
meta
;quit;
'));
end;
array pat[&sqlobs] $8 (&pat.);
array tyt[&sqlobs] $64 (&tyt.);
array fot[&sqlobs] $64 (&fot.);
do i=1 to &sqlobs;
call symputx('pat',pat[i]);
call symputx('tyt',tyt[i]);
call symputx('fot',fot[i]);
call symputx('pge',put(i,1.));
rc=dosubl('
ods rtf prepage=
"^S={outputwidth=100% just=c font_size=11pt font_face=arial} {Student Clinical Trial Gebder=&pat.}^{newline}{&tyt}";
proc report data=sashelp.class (where=(sex="&pat")) nowd split="#" missing;
run;quit;
ods rtf text="^S={outputwidth=100% just=r font_size=9pt} Page &pge of &sqlobs";
ods rtf text="^S={outputwidth=100% just=l font_size=8pt font_style=italic} {Program: c:/utl/dm.sas_&sysdate}";
ods rtf text="^S={outputwidth=100% just=l font_size=8pt font_style=italic} {Log: c:/utl/dm.log_&sysdate}";
ods rtf text="^S={outputwidth=100% just=l font_size=8pt font_style=italic} {&fot}";
');
end;
stop;
run;quit;
ods rtf close;
ods listing;
* _ _ _ __ _ _ ___ ___
_ _| |_| | _ __| |_ / _| | __ _ _ __ / |/ _ \ / _ \
| | | | __| |_____| '__| __| |_| |/ _` | '_ \| | | | | | | |
| |_| | |_| |_____| | | |_| _| | (_| | | | | | |_| | |_| |
\__,_|\__|_| |_| \__|_| |_|\__,_|_| |_|_|\___/ \___/
;
%Macro utl_rtflan100
(
style=utl_rtflan100,
frame=box,
rules=groups,
bottommargin=1.0in,
topmargin=1.5in,
rightmargin=1.0in,
cellheight=10pt,
cellpadding = 7,
cellspacing = 3,
leftmargin=.75in,
borderwidth = 1
) / Des="SAS Rtf Template for CompuCraft";
options orientation=landscape;run;quit;
ods path work.templat(update) sasuser.templat(update) sashelp.tmplmst(read);
Proc Template;
define style &Style;
parent=styles.rtf;
replace body from Document /
protectspecialchars=off
asis=on
bottommargin=&bottommargin
topmargin =&topmargin
rightmargin =&rightmargin
leftmargin =&leftmargin
;
replace color_list /
'link' = blue
'bgH' = _undef_
'fg' = black
'bg' = _undef_;
replace fonts /
'TitleFont2' = ("Arial, Helvetica, Helv",11pt,Bold)
'TitleFont' = ("Arial, Helvetica, Helv",11pt,Bold)
'HeadingFont' = ("Arial, Helvetica, Helv",10pt)
'HeadingEmphasisFont' = ("Arial, Helvetica, Helv",10pt,Italic)
'StrongFont' = ("Arial, Helvetica, Helv",10pt,Bold)
'EmphasisFont' = ("Arial, Helvetica, Helv",10pt,Italic)
'FixedFont' = ("Courier New, Courier",9pt)
'FixedEmphasisFont' = ("Courier New, Courier",9pt,Italic)
'FixedStrongFont' = ("Courier New, Courier",9pt,Bold)
'FixedHeadingFont' = ("Courier New, Courier",9pt,Bold)
'BatchFixedFont' = ("Courier New, Courier",7pt)
'docFont' = ("Arial, Helvetica, Helv",10pt)
'FootFont' = ("Arial, Helvetica, Helv", 9pt)
'StrongFootFont' = ("Arial, Helvetica, Helv",8pt,Bold)
'EmphasisFootFont' = ("Arial, Helvetica, Helv",8pt,Italic)
'FixedFootFont' = ("Courier New, Courier",8pt)
'FixedEmphasisFootFont'= ("Courier New, Courier",8pt,Italic)
'FixedStrongFootFont' = ("Courier New, Courier",7pt,Bold);
replace GraphFonts /
'GraphDataFont' = ("Arial, Helvetica, Helv",8pt)
'GraphAnnoFont' = ("Arial, Helvetica, Helv",8pt)
'GraphValueFont' = ("Arial, Helvetica, Helv",10pt)
'GraphUnicodeFont' = ("Arial, Helvetica, Helv",10pt)
'GraphLabelFont' = ("Arial, Helvetica, Helv",10pt,Bold)
'GraphLabel2Font' = ("Arial, Helvetica, Helv",10pt,Bold)
'GraphFootnoteFont' = ("Arial, Helvetica, Helv",8pt)
'GraphTitle1Font' = ("Arial, Helvetica, Helv",11pt,Bold)
'GraphTitleFont' = ("Arial, Helvetica, Helv",11pt,Bold);
style table from table /
outputwidth=100%
protectspecialchars=off
asis=on
background = colors('tablebg')
frame=&frame
rules=&rules
cellheight = &cellheight
cellpadding = &cellpadding
cellspacing = &cellspacing
bordercolor = colors('tableborder')
borderwidth = &borderwidth;
replace Footer from HeadersAndFooters
/ font = fonts('FootFont') just=left asis=on protectspecialchars=off ;
replace FooterFixed from Footer
/ font = fonts('FixedFootFont') just=left asis=on protectspecialchars=off;
replace FooterEmpty from Footer
/ font = fonts('FootFont') just=left asis=on protectspecialchars=off;
replace FooterEmphasis from Footer
/ font = fonts('EmphasisFootFont') just=left asis=on protectspecialchars=off;
replace FooterEmphasisFixed from FooterEmphasis
/ font = fonts('FixedEmphasisFootFont') just=left asis=on protectspecialchars=off;
replace FooterStrong from Footer
/ font = fonts('StrongFootFont') just=left asis=on protectspecialchars=off;
replace FooterStrongFixed from FooterStrong
/ font = fonts('FixedStrongFootFont') just=left asis=on protectspecialchars=off;
replace RowFooter from Footer
/ font = fonts('FootFont') asis=on protectspecialchars=off just=left;
replace RowFooterFixed from RowFooter
/ font = fonts('FixedFootFont') just=left asis=on protectspecialchars=off;
replace RowFooterEmpty from RowFooter
/ font = fonts('FootFont') just=left asis=on protectspecialchars=off;
replace RowFooterEmphasis from RowFooter
/ font = fonts('EmphasisFootFont') just=left asis=on protectspecialchars=off;
replace RowFooterEmphasisFixed from RowFooterEmphasis
/ font = fonts('FixedEmphasisFootFont') just=left asis=on protectspecialchars=off;
replace RowFooterStrong from RowFooter
/ font = fonts('StrongFootFont') just=left asis=on protectspecialchars=off;
replace RowFooterStrongFixed from RowFooterStrong
/ font = fonts('FixedStrongFootFont') just=left asis=on protectspecialchars=off;
replace SystemFooter from TitlesAndFooters / asis=on
protectspecialchars=off just=left;
end;
run;
quit;
%Mend utl_rtflan100;
*_
| | ___ __ _
| |/ _ \ / _` |
| | (_) | (_| |
|_|\___/ \__, |
|___/
;
4348 %symdel pge pat tyt fot/ nowarn;
4349 data _null_;
4350 * get meta data;
4351 if _n_=0 then do;
4352 rc=%sysfunc(dosubl('
4353 proc sql noprint ;
4354 select
4355 quote(pat1)
4356 ,quote(tyt1)
4357 ,quote(fot1)
4358 into
4359 :pat separated by ","
4360 ,:tyt separated by ","
NOTE: PROCEDURE SQL used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 3717.31k
OS Memory 19696.00k
Timestamp 04/09/2017 03:25:39 PM
Step Count 235 Switch Count 0
4361 ,:fot separated by ","
4362 from
4363 meta
4364 ;quit;
4365 '));
4366 end;
4367 array pat[&sqlobs] $8 (&pat.);
SYMBOLGEN: Macro variable SQLOBS resolves to 2
SYMBOLGEN: Macro variable PAT resolves to "M","F"
4368 array tyt[&sqlobs] $64 (&tyt.);
SYMBOLGEN: Macro variable SQLOBS resolves to 2
SYMBOLGEN: Macro variable TYT resolves to "Invoice 2378675 for
Rural Partipicpants ","Invoice 288675 for Urban
Partipicpants "
4369 array fot[&sqlobs] $64 (&fot.);
SYMBOLGEN: Macro variable SQLOBS resolves to 2
SYMBOLGEN: Macro variable FOT resolves to "see Protocol
1013.6(Oncology) ","see Protocol
10883.6(Analgesics) "
4370 do i=1 to &sqlobs;
SYMBOLGEN: Macro variable SQLOBS resolves to 2
4371 call symputx('pat',pat[i]);
4372 call symputx('tyt',tyt[i]);
4373 call symputx('fot',fot[i]);
4374 call symputx('pge',put(i,1.));
4375 rc=dosubl('
4376 ods rtf prepage=
4377 "^S={outputwidth=100% just=c font_size=11pt
4377! font_face=arial} {Student Clinical Trial
4377! Gebder=&pat.}^{newline}{&tyt}";
4378 proc report data=sashelp.class (where=(sex="&pat"))
4378! nowd split="#" missing;
4379 run;quit;
4380 ods rtf text="^S={outputwidth=100% just=r
4380! font_size=9pt} Page &pge of &sqlobs";
4381 ods rtf text="^S={outputwidth=100% just=l
4381! font_size=8pt font_style=italic} {Program:
4381! c:/utl/dm.sas_&sysdate}";
4382 ods rtf text="^S={outputwidth=100% just=l
4382! font_size=8pt font_style=italic} {Log:
4382! c:/utl/dm.log_&sysdate}";
4383 ods rtf text="^S={outputwidth=100% just=l
4383! font_size=8pt font_style=italic} {&fot}";
4384 ');
4385 end;
4386 stop;
4387 run;
SYMBOLGEN: Macro variable PAT resolves to M
SYMBOLGEN: Macro variable TYT resolves to Invoice 2378675 for Rural Partipicpants
NOTE: Writing RTF Body file: sasrtf.rtf
SYMBOLGEN: Macro variable PAT resolves to M
4387! quit;
NOTE: There were 10 observations read from the data set SASHELP.CLASS.
WHERE sex='M';
NOTE: PROCEDURE REPORT used (Total process time):
real time 0.10 seconds
user cpu time 0.03 seconds
system cpu time 0.07 seconds
memory 10927.62k
OS Memory 24324.00k
Timestamp 04/09/2017 03:25:39 PM
Step Count 235 Switch Count 0
SYMBOLGEN: Macro variable PGE resolves to 1
SYMBOLGEN: Macro variable SQLOBS resolves to 2
SYMBOLGEN: Macro variable SYSDATE resolves to 09APR17
SYMBOLGEN: Macro variable SYSDATE resolves to 09APR17
SYMBOLGEN: Macro variable FOT resolves to see Protocol 1013.6(Oncology)
SYMBOLGEN: Macro variable PAT resolves to F
SYMBOLGEN: Macro variable TYT resolves to Invoice 288675 for Urban Partipicpants
SYMBOLGEN: Macro variable PAT resolves to F
NOTE: There were 9 observations read from the data set SASHELP.CLASS.
WHERE sex='F';
NOTE: PROCEDURE REPORT used (Total process time):
real time 0.06 seconds
user cpu time 0.01 seconds
system cpu time 0.03 seconds
memory 11190.09k
OS Memory 24836.00k
Timestamp 04/09/2017 03:25:40 PM
Step Count 235 Switch Count 0
SYMBOLGEN: Macro variable PGE resolves to 2
SYMBOLGEN: Macro variable SQLOBS resolves to 2
SYMBOLGEN: Macro variable SYSDATE resolves to 09APR17
SYMBOLGEN: Macro variable SYSDATE resolves to 09APR17
SYMBOLGEN: Macro variable FOT resolves to see Protocol 10883.6(Analgesics)
NOTE: DATA statement used (Total process time):
real time 0.59 seconds
user cpu time 0.17 seconds
system cpu time 0.29 seconds
memory 11190.09k
OS Memory 24836.00k
Timestamp 04/09/2017 03:25:40 PM
Step Count 235 Switch Count 3
4388 ods rtf close;
4389 ods listing;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.