BookmarkSubscribeRSS Feed
RameshReddy
Calcite | Level 5

Hello,

I am executing macro based on condition ,in that macro i want to execute another macro program, its not working ,can any one help one this .? for your referennce i given example below.

%macro A;

%if  Count=0 %then %do;

proc print data=a;

run;

%else %if Count>0 %then %do;

ods pdf file='TEST/TEST....pdf';

Proc report Data=TEST;

run;

%put 'TESTING';

%macro B;

%if  Count1=0 %then %do;

proc print data=TEST2;

run;

%else %if Count1>0 %then %do;

proc print data=TEST3;

run;

%end;

%mend B;

%B;

proc report dat=Test2 ;

run;

ods pdf close;

%end;

%mend A;

%A;

Thanks,

Ramesh

%end;

%mend A;

%A;

1 REPLY 1
Cynthia_sas
SAS Super FREQ

Hi:

  I see a few problems and issues. First, in your %IF test, you test like this:

%if Count = 0 and %if Count1 = 0 

I am not sure what COUNT and COUNT1 are. If they are DATA SET variables, then your macro needs more work. Generally, in a %IF statement, you are testing MACRO variables, such as:

%if &COUNT=0 %then %do;

There is a huge difference between referencing COUNT and &COUNT.

  Next, I have never, in all my years of doing macro programming (and that is a LOT of years), nested macro DEFINITIONS inside each other, the way you show. I have always followed the practice of defining my macro programs separately, some thing like this:

%macro a;

...macro programming statements to generate code.... and possibly have a call to another macro ...

%b

%mend a;

%macro b;

... macro programming statements to generate code ...

%mend b;

and then either have a new macro program to run everything :

%macro runit;

%a;

%mend runit;

%runit

OR just invoke the first macro that contains the call to the second macro:

%a

But, given that I don't understand what you are trying to do in your macro programs, I wonder whether you actually need 2 macros at all. The rule of thumb is that you need to start with a working SAS program without any macro variables and get your program working first. That means making sure all your proc prints and proc reports work correctly and that your ODS PDF code generates the file you want.

Next, the best thing to do is use %LET statements to assign the values of the macro variables you think you will need and test your program using these macro variables. If you are going to generate huge chunks of code inside a macro program, then you would need to define your macro variables and use them inside a macro program with macro conditional logic. You have to iron out for yourself and figure out where COUNT or &COUNT comes from. The way things are written now, I would expect things not to work.

Also, in your code, you show this

ods pdf file='TEST/TEST....pdf';

for the name of your PDF file. Usually, you use multiple periords in a file name because you are going to use macro variables in the name. But, macro variables must be enclosed in double quotes to be resolved and you have too many periods in the name. I would expect to see something like this:

ods pdf file="mydir/&myfilename.&count..pdf"; 

with the FILE= option in double quotes and some macro variables in the name and/or path specifications.

This is a really good introduction to macro processing and may help you figure out the best way to write your macro code. http://www2.sas.com/proceedings/sugi28/056-28.pdf

cynthia

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 1 reply
  • 1111 views
  • 0 likes
  • 2 in conversation