BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lbarwick
Quartz | Level 8

Morning,

 

I hope I am posting this in the right section. I am using ods pdf to generate a report and want to conditionally execute some proc report statements based on macro variables. I have wrapped the proc reports in a macro and am using %if %then %else to direct the printing.

 

The issue I am running into is that my last %else condition is not executing in the output. The log shows that the macro logic worked as it should but the actual PDF file is missing the table that was supposed to print.

 

I have included the below code (with comments - hopefully it is clear) and log:

 

 

%macro grpprint / mindelimiter=',';

%*For Standard or Data request types include value of &groupdefine as an ods text line,
	further, print either grpstdcdrcp2 or grpstdcts table depending on the &groupdefine value;
%if &reqapp in (Standard,Data) %then %do;
ods region x = 0.50 in
	   y = 1.50 in;
ods text = "^{style[font_face='arial' fontsize=10pt]Participants grouped by: &groupdefine}";

	%*if Standard or Data request type and &groupdefine is one of two values below, print grpstdcdrcp2;
	%if &groupdefine in (Final Clinical Diagnosis,Pathological Diagnosis) %then %do;
	options linesize=256;
	ods region x = 0.50 in
		   y = 1.75 in
		   width = 7.25 in; 

	proc report data=grpstdcdrcp2 nowd style={just=l};
	column ptcdxcat1 ptcdxnum1 ptcgold ptcnumpt1 ptcinex1;
		define ptcdxcat1 / display 'Dx category'
		style(column)={cellwidth=1.20in};

		define ptcdxnum1 / display 'Dx numbers (click for labels)'
		style(header)={url="&dxlink" color=blue textdecoration=underline}
		style(column)={cellwidth=1.20in};

		define ptcgold / display 'GOLD stage'
		style(column)={cellwidth=1.20in};

		define ptcnumpt1 / display 'Participants required'
		style(column)={cellwidth=1.20in};

		define ptcinex1 / display "Other inclusion & exclusion"
		style(column)={cellwidth=2.00in};
	run;
	%end;

	%*otherwise if Standard or Data request type and &groupdefine is value below, print grpstdcts;
	%else %if &groupdefine = Radiological Diagnosis %then %do;
	options linesize=256;
	ods region x = 0.50 in
		   y = 1.75 in
		   width = 7.25 in; 
	proc report data=grpstdcts nowd style={just=l};
	column ptcdxnum2 ptcnumpt2 ptcinex2;
		define ptcdxnum2 / display 'Dx numbers (click for labels)'
		style(header)={url="&dxlink" color=blue textdecoration=underline}
		style(column)={cellwidth=1.25in};
		define ptcnumpt2 / display 'Participants required'
		style(column)={cellwidth=1.25in};
		define ptcinex2 / display 'Other inclusion/exclusion'
		style(column)={cellwidth=2.00in};
	run;
	%end;
%end;

%*otherwise if Express request type, do not execute the above and instead print the grpexp table;
%else %if &reqapp=Express %then %do;
options linesize=256;
ods region x = 0.50 in
	   y = 1.50 in
	   width = 7.25 in; 

proc report data=grpexp nowd style={just=l};
column ptcdisgrp ptcdissev ptcnumpt3;
	define ptcdisgrp / display 'Disease group'
	style(column)={cellwidth=1.25in};

	define ptcdissev / display 'Disease severity'
	style(column)={cellwidth=1.25in};

	define ptcnumpt3 / display 'Participants required'
	style(column)={cellwidth=1.25in};

run;
%end;
%mend grpprint;
%grpprint;

 

Log:

2988  %macro grpprint / mindelimiter=',';
2989
2990  %*For Standard or Data request types include value of &groupdefine as an ods text line,
2991      further, print either grpstdcdrcp2 or grpstdcts table depending on the &groupdefine value;
2992  %if &reqapp in (Standard,Data) %then %do;
2993  ods region x = 0.50 in
2994             y = 1.50 in;
2995  ods text = "^{style[font_face='arial' fontsize=10pt]Participants grouped by: &groupdefine}";
2996
2997      %*if Standard or Data request type and &groupdefine is one of two values below, print grpstdcdrcp2;
2998      %if &groupdefine in (Final Clinical Diagnosis,Pathological Diagnosis) %then %do;
2999      options linesize=256;
3000      ods region x = 0.50 in
3001                 y = 1.75 in
3002                 width = 7.25 in;
3003
3004      proc report data=grpstdcdrcp2 nowd style={just=l};
3005      column ptcdxcat1 ptcdxnum1 ptcgold ptcnumpt1 ptcinex1;
3006          define ptcdxcat1 / display 'Dx category'
3007          style(column)={cellwidth=1.20in};
3008
3009          define ptcdxnum1 / display 'Dx numbers (click for labels)'
3010          style(header)={url="&dxlink" color=blue textdecoration=underline}
3011          style(column)={cellwidth=1.20in};
3012
3013          define ptcgold / display 'GOLD stage'
3014          style(column)={cellwidth=1.20in};
3015
3016          define ptcnumpt1 / display 'Participants required'
3017          style(column)={cellwidth=1.20in};
3018
3019          define ptcinex1 / display "Other inclusion & exclusion"
3020          style(column)={cellwidth=2.00in};
3021      run;
3022      %end;
3023
3024      %*otherwise if Standard or Data request type and &groupdefine is value below, print grpstdcts;
3025      %else %if &groupdefine = Radiological Diagnosis %then %do;
3026      options linesize=256;
3027      ods region x = 0.50 in
3028                 y = 1.75 in
3029                 width = 7.25 in;
3030      proc report data=grpstdcts nowd style={just=l};
3031      column ptcdxnum2 ptcnumpt2 ptcinex2;
3032          define ptcdxnum2 / display 'Dx numbers (click for labels)'
3033          style(header)={url="&dxlink" color=blue textdecoration=underline}
3034          style(column)={cellwidth=1.25in};
3035          define ptcnumpt2 / display 'Participants required'
3036          style(column)={cellwidth=1.25in};
3037          define ptcinex2 / display 'Other inclusion/exclusion'
3038          style(column)={cellwidth=2.00in};
3039      run;
3040      %end;
3041  %end;
3042
3043  %*otherwise if Express request type, do not execute the above and instead print the grpexp table;
3044  %else %if &reqapp=Express %then %do;
3045  options linesize=256;
3046  ods region x = 0.50 in
3047             y = 1.50 in
3048             width = 7.25 in;
3049
3050  proc report data=grpexp nowd style={just=l};
3051  column ptcdisgrp ptcdissev ptcnumpt3;
3052      define ptcdisgrp / display 'Disease group'
3053      style(column)={cellwidth=1.25in};
3054
3055      define ptcdissev / display 'Disease severity'
3056      style(column)={cellwidth=1.25in};
3057
3058      define ptcnumpt3 / display 'Participants required'
3059      style(column)={cellwidth=1.25in};
3060
3061  run;
3062  %end;
3063  %mend grpprint;
3064  %grpprint;
MLOGIC(GRPPRINT):  Beginning execution.
SYMBOLGEN:  Macro variable REQAPP resolves to Express
MLOGIC(GRPPRINT):  %IF condition &reqapp in (Standard,Data) is FALSE
SYMBOLGEN:  Macro variable REQAPP resolves to Express
MLOGIC(GRPPRINT):  %IF condition &reqapp=Express is TRUE
MPRINT(GRPPRINT):   options linesize=256;
MPRINT(GRPPRINT):   ods region x = 0.50 in y = 1.50 in width = 7.25 in;
MPRINT(GRPPRINT):   proc report data=grpexp nowd style={just=l};
MPRINT(GRPPRINT):   column ptcdisgrp ptcdissev ptcnumpt3;
MPRINT(GRPPRINT):   define ptcdisgrp / display 'Disease group' style(column)={cellwidth=1.25in};
MPRINT(GRPPRINT):   define ptcdissev / display 'Disease severity' style(column)={cellwidth=1.25in};
MPRINT(GRPPRINT):   define ptcnumpt3 / display 'Participants required' style(column)={cellwidth=1.25in};
MPRINT(GRPPRINT):   run;
NOTE: There were 2 observations read from the data set WORK.GRPEXP.
NOTE: PROCEDURE REPORT used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


MLOGIC(GRPPRINT):  Ending execution.

The macro debug code in the log at line 3064 seems to indicate that the value of &reqapp resolved to Express and that my %if &reqapp=Express is TRUE. I then see that the proc report read 2 observations; however, as mentioned above, the output PDF file does not contain the results of the proc report. I have tested the hard code and run the macro with &reqapp evaluated as Standard or Data and everything works perfectly. I have also tried isolating the 'Express' portion within the grpprint macro and it works fine, e.g.:

 


%macro grpprint / mindelimiter=',';

%*if Express request type, print the grpexp table;
%if &reqapp=Express %then %do;
options linesize=256;
ods region x = 0.50 in
	   y = 1.50 in
	   width = 7.25 in; 

proc report data=grpexp nowd style={just=l};
column ptcdisgrp ptcdissev ptcnumpt3;
	define ptcdisgrp / display 'Disease group'
	style(column)={cellwidth=1.25in};

	define ptcdissev / display 'Disease severity'
	style(column)={cellwidth=1.25in};

	define ptcnumpt3 / display 'Participants required'
	style(column)={cellwidth=1.25in};

run;
%end;

Is there something wrong with my %if %do %else logic? Am I trying to do too much within one macro?

 

Thanks,

Lucas

 

1 ACCEPTED SOLUTION

Accepted Solutions
lbarwick
Quartz | Level 8

So I've been using 9.3 (current standard w/in my organization), and learned ODS Layout was production in 9.4. I just tested my code in 9.4, and after making a couple tweaks to accommodate the updated software everything is working just as it should. Glad it seems like a pre-production issue and nothing wrong with my code.

View solution in original post

11 REPLIES 11
tomrvincent
Rhodochrosite | Level 12
I don't see an 'ods pdf' to begin or a 'ods pdf close' at the end.

I'd suggest getting rid of as much junk as you can to test that at least one record goes out to the pdf and then you can add all the rest of the junk back in.
lbarwick
Quartz | Level 8

Hi,

 

Sorry - the ods pdf and close statements were not included in the test code, I have multiple other macros within those and didn't want to include everything. I suppose I should've just included to abbreviate my example. 

 

I mentioned at the end that I did try just the last proc report and it worked fine, it seems the parent %if are preventing the last %if from printing. I will try to do some more testing.

tomrvincent
Rhodochrosite | Level 12
Another suggestion is to have the express code in a separate macro...isolating it might make it easier to test.
ballardw
Super User

You also have a number of macro variables that we do not see any setting code for. Since you say this stuff is nested then perhaps you are getting a timing issue of values of macro variables &reqapp or &groupdefine used in your %if and when the macro executes.

 

ODS Region could have another issue if your output won't actually fit into the given sizes. I'm not sure what region height would be used with the dimensions you provide and that might be an issue with ODS Layout settings scattered between multiple macros.

lbarwick
Quartz | Level 8
The macro variables are global and set before the ods pdf step even begins. The region settings are fine as I have tested the Express portion of the problematic macro by itself and the table prints just fine.
Tom
Super User Tom
Super User

You either closed the PDF destination before running that macro.

Or you haven't yet closed the PDF destination and you are trying to look at an incomplete or old version of the file?

lbarwick
Quartz | Level 8

I only have one pdf close statement at the end and I run the whole ods pdf code each time I test. I check timestamp of output file before opening. There are no errors/warnings in log. 

 

I tried removing the Express portion and inserting it into it's own macro and I get the same result.

lbarwick
Quartz | Level 8

Something interesting I just discovered - immediately preceding %grpprint macro, I have some non-macrotized ods layout code that configures a page (we'll call it 'Resource Utilization') with four ods text lines (for header, footer, and a table header). That code is below:

 

*Resource Utilization page;
ods layout start width=8.49in
height=10.99in;

*header;
ods region x = &headerx in
		   y = 0.40 in;
ods text = "^{style[font_face='arial' fontsize=20pt
			just=l fontweight=bold] Lung Tissue Research Consortium}"; 

ods region x = 0.53 in
		   y = 0.75 in;
ods text = "^{style[font_face='arial' fontsize=16pt
			just=l fontweight=bold] Investigator Request for Materials}"; 

ods region x = &headerx in
		   y = 0.95 in;
ods text="__________________________________________________________________________________________________________"; 
*end header;

*footer;
ods region x = 0.50 in
		   y = 10.50 in; 
ods text = "^{style[font_face='arial' fontsize=9pt just=left fontstyle=italic]&reqfooter}"; 

ods region x = 0.50 in
		   y = 10.50 in; 
ods text = "^{style[font_face='arial' fontsize=9pt just=center fontstyle=italic]Page  ^{thispage} of  ^{lastpage}}"; 

ods region x = 0.50 in
		   y = 10.50 in
		   width = 7.25 in;
ods text = "^{style[font_face='arial' fontsize=9pt just=right fontstyle=italic]Contract Number: HHSN268201600002I}"; 
*end footer;

ods region x = 0.50 in
		   y = 1.25 in;
ods text = "^{style[font_face='arial' fontsize=12pt textdecoration=underline font_weight=bold]Funding}";

ods layout end;
*end resource utilization page;

Now, if I cut/paste this Resource Utilization portion of code (from ods layout start through ods layout end;) and insert it above another ods layout block, the output fails to print the ods layout that now follows the Resource Utilization ods layout portion. The output will contain the ods layout portions that follow the portion that doesn't print. So it seems as if the portion immediately following the Resource Utilization is being skipped in the output. 

 

As far as I can tell the Resource Utilization ods layout code is identical in syntax/structure as all the other ods layout portions of my ods pdf code. 

ballardw
Super User

Are you working with ODS LAYOUT ABSOLUTE or ODS LAYOUT GRIDDED?

Perhaps this bit from the documentation of LAYOUT ABSOLUTE may apply:

Absolute layout is restricted to a single page. If the output is too large to fit in the fixed-size container, the output is discarded. You receive a blank region and a warning in your log. Absolute layout is perfectly suited for static types of output.

 

If your table doesn't appear in the output perhaps it is attempting to exceed a "single page" in your overall document relative to where it starts or ends.

lbarwick
Quartz | Level 8
I am using absolute. The output fits on one page and I have confirmed this by tweaking various bits to run pieces separately and verifying what the output looks like in the final PDF output. Additionally, I am receiving no errors or warnings.
lbarwick
Quartz | Level 8

So I've been using 9.3 (current standard w/in my organization), and learned ODS Layout was production in 9.4. I just tested my code in 9.4, and after making a couple tweaks to accommodate the updated software everything is working just as it should. Glad it seems like a pre-production issue and nothing wrong with my code.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 11 replies
  • 4168 views
  • 0 likes
  • 4 in conversation