BookmarkSubscribeRSS Feed
kmardinian
Quartz | Level 8

Hi, this may be a bit complicated to explain in words, but I have a list of different tests that either have true or false results. I would like the footnotes that are located in a separate excel document to populate when a particular test contains false results. Each test contains its own footnote. Test 1 has Foot_1, Test 2 has Foot_2, etc.

 

I would like to create an if then statement so that only the footnotes of the tests that contain false results show up in my pdf output.So far, I have created macro variables for all my footnotes (&Foot_1, &Foot_2, etc.)

 

I have tried this, which does not work, but I do not think I can use an if then statement in my proc report statement.

So I was trying it this way, which is not working.

%macro foot(var,testnumber);

data ab; set t6_&vorder (where=(&var = 'False')); run;
proc sql noprint; select count(unique(SUBNUM)) into :ab1 from ab; quit; %put &ab1=&ab1;

data ab1_&vorder;
set ab;
if &ab1>0 then do;
*use macro variable to populate footnote;
foot_&vorder=foot_&vorder; ?????????????????????????????
end;
vorder=&vorder;
run;


%mend;

%foot(Test1,1)

 

Any help is much appreciated, thank you!

 

 

9 REPLIES 9
kmardinian
Quartz | Level 8

If helpful,

 

this is the statement I use in my proc report to call my footnotes.

 

   compute after _page_/left style={bordertopcolor=black bordertopwidth=1 just=l font_face='Courier New' font_size=8pt};
    line "&foot_1.";
    line "&foot_2.";
    line "&foot_3.";
    line "&foot_4.";
   endcomp;
  run;
ods pdf close;

Reeza
Super User
What version of SAS do you have? 9.4 M5+?
kmardinian
Quartz | Level 8

Hi Reeza,

 

I am using SAS Base version 9.4 TS Level 1M4

 

Thank you!

ballardw
Super User

What macro variable do you have to indicate that the foot note should be placed? It isn't quite clear.

You also reference a macro variables &ab and &vorder that is not defined or described in any way. So where do they come from and what values do they have.

 

And a foot note is NOT going to reference something in an Excel document. You will need to bring it into SAS as data and then manipulate that.

 

Here is one way to use a macro variable to select a single footnote for output. Each of the %do / %end code bits enclose a separate bit of code that is provided to the compiler. The last example does not generate a footnote because there is not a defined one for the value 4.

%macro dummy (which);
   proc print data=sashelp.class (obs=3);
      var name sex;
   %if &which=1 %then %do;
   Footnote1 "This is the first footnote";
   %end;
   %if &which=2 %then %do;
   Footnote1 "This is the second footnote";
   %end;
   %if &which=3 %then %do;
   Footnote1 "This is the third footnote";
   %end;
   run; footnote; /* turn off further footnotes*/
%mend ;

%dummy(1)
%dummy(2)
%dummy(3)
%dummy(4)
kmardinian
Quartz | Level 8

 

I create the macro variable &ab to calculate whether the test had any abnormal results. So if &ab > 0, I would add the footnote for that test. The &vorder macro variable was to number each test.

 

Could I maybe use the &ab macro variable in the code you provided, like this?

 

 

%macro dummy (which);
   proc print data=sashelp.class (obs=3);
      var name sex;
   %if &abtest1>0 %then %do;
   Footnote1 "This is the first footnote";
   %end;
   %if &abtest2>0 %then %do;
   Footnote1 "This is the second footnote";
   %end;
   %if &abtest3>0 %then %do;
   Footnote1 "This is the third footnote";
   %end;
   run; footnote; /* turn off further footnotes*/
%mend ;

 

Also, if multiple footnotes are needed, will they all populate even though they are all called 'Footnote1'?

ballardw
Super User

@kmardinian wrote:

 

I create the macro variable &ab to calculate whether the test had any abnormal results. So if &ab > 0, I would add the footnote for that test. The &vorder macro variable was to number each test.

 

Could I maybe use the &ab macro variable in the code you provided, like this?

 

 

%macro dummy (which);
   proc print data=sashelp.class (obs=3);
      var name sex;
   %if &abtest1>0 %then %do;
   Footnote1 "This is the first footnote";
   %end;
   %if &abtest2>0 %then %do;
   Footnote1 "This is the second footnote";
   %end;
   %if &abtest3>0 %then %do;
   Footnote1 "This is the third footnote";
   %end;
   run; footnote; /* turn off further footnotes*/
%mend ;

 

Also, if multiple footnotes are needed, will they all populate even though they are all called 'Footnote1'?


It is up to you to place what you want within each bloc of %do %end statements. If the block should contain more than one put them there. The idea here is that only one block is used. If you use a single variable to select multiple footnotes then each %do/%end block would require different footnote numbers. If you have multiple definitions for Footnote1 in effect when the code runs only the last defined will be used.

You can place the value of a macro variable into a footnote with: Footnote  "This is text related to &macrovar" ; Note that the quotes MUST be double quotes for the macro variable to resolve.

 

Generally it is often a bad idea to use a variable in a macro that is ether not passed into it as a parameter or created in the macro. Bad things can happen if you use the same name in different places for different values/uses.

 

You might consider use of Proc ODSTEXT instead as it may be more flexible than footnotes and since there is no limit on the number of lines/ statements involved. Also you can test the text generated without a procedure unlike the Footnote which requires use of some procedure to generate output.

 

%macro dummy (abtest, othertext);

Proc odstext;
%if &abtest. > 0 %then %do;
   P "This is the text shown when macro variable ABTEST is greater than 0.
   Includes additional text &Othertext.";
%end;
%if &abtest. =1  %then %do;
   P "This is the text shown when macro variable ABTEST is exactly 1.";
%end;
%if &abtest. > 2 %then %do;
   P "This is the text shown when ABTEST > 2: &abtest. .";
%end;
run; 
%mend;

%dummy (1, fashion week)
%dummy (a, what)
%dummy (3, longer example text)

 

Which will demonstrate a problem with using the comparison &abtest > 0  in macro code since everything is text: Text values can be "greater than 0" even when not numeric characters.

kmardinian
Quartz | Level 8

Hi ballardw, I appreciate you taking the time to help me with this. But I am still a bit confused.

 

Just to clarigy, my macro variable &ab1 is actually a numeric variable and is >0 for certain tests.

 

data ab; set t6_&vorder (where=(&var = 'False')); run;
proc sql noprint; select count(unique(SUBNUM)) into :ab1 from ab; quit; %put &ab1=&ab1;

 

I am still stuck on one issue. I will never know how many tests (there are 10 total tests) will have more than 0 false results. So I would need to create combinations of all the possible scenarios for each %do %end statment. This would be so many different combinations!

 

Is there no possibility of coding it so that the footnote is a macro variable that I could then use in my proc report statement. For example:

 

%macro dummy (test,testnumber);
   proc print data=sashelp.class (obs=3);
      var name sex;
   %if &abtest1>0 %then %do;
   Footnote_&testnumber "This is the first footnote";
   %end;

   run; footnote; /* turn off further footnotes*/
%mend ;

dummy(test1,1);
dummy(test2,2);

Proc Report Statement:
  compute after _page_/left style={bordertopcolor=black bordertopwidth=1 just=l font_face='Courier New' font_size=8pt};
    line "&footnote_1.";
    line "&footnote_2.";
   endcomp;
  run;
ods pdf close;

 

ballardw
Super User

@kmardinian wrote:

Hi ballardw, I appreciate you taking the time to help me with this. But I am still a bit confused.

 

Just to clarigy, my macro variable &ab1 is actually a numeric variable and is >0 for certain tests.

 

data ab; set t6_&vorder (where=(&var = 'False')); run;
proc sql noprint; select count(unique(SUBNUM)) into :ab1 from ab; quit; %put &ab1=&ab1;

 

I am still stuck on one issue. I will never know how many tests (there are 10 total tests) will have more than 0 false results. So I would need to create combinations of all the possible scenarios for each %do %end statment. This would be so many different combinations!

 

Is there no possibility of coding it so that the footnote is a macro variable that I could then use in my proc report statement. For example:

 

%macro dummy (test,testnumber);
   proc print data=sashelp.class (obs=3);
      var name sex;
   %if &abtest1>0 %then %do;
   Footnote_&testnumber "This is the first footnote";
   %end;

   run; footnote; /* turn off further footnotes*/
%mend ;

dummy(test1,1);
dummy(test2,2);

Proc Report Statement:
  compute after _page_/left style={bordertopcolor=black bordertopwidth=1 just=l font_face='Courier New' font_size=8pt};
    line "&footnote_1.";
    line "&footnote_2.";
   endcomp;
  run;
ods pdf close;

 


Your footnote macro variables created in the first macro, if they were actually created, cease to exist after the macro runs so that text would not be available in proc report.

The footnote syntax is Footnote1 footnote2 etc. The code you have with footnote_1 etcs will generate syntax errors.

 

I think it is time for you to provide either example data or cast your whole problem as using a SAS supplied set like SASHELP.CLASS,

do something to generate whatever that abtest variable(s) look like and the actual NON-macro code you want generated by any macro. I can't quite follow what you are attempting with mixing statements like FOOTNOTE and similarly named macro variables (that don't exist). You should show the entire Proc code for each provided example including your actual footnote values. Repeat NO macro variables at all. You can indicate, preferably on a line by line basis dependencies expected.

 

For the cases related to "I will never know how many tests (there are 10 total tests) will have more than 0 false results. So I would need to create combinations of all the possible scenarios for each %do %end statment. " show at least some of the combinations.

 

Also remember that macro calls require the % at the front of the name. A simple call such as dummy() will generate errors

 

kmardinian
Quartz | Level 8

Hi Ballardw,

 

How would I call the footnotes for each test in my proc report statement, if they are all called Footnote1? Can I create macro variable for the footnote? So that all the tests that have more than 0 false tests have their own footnote?

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 9 replies
  • 2298 views
  • 0 likes
  • 3 in conversation