DATA Step, Macro, Functions and more

Conditional Processing With Macro Vars

Super Contributor
Posts: 358

Conditional Processing With Macro Vars

Hi All:

I'm no great shakes with Macro vars and processing, so I hope someone here can help out.

I have this program:


%let period=Daily;
%include source(DAILY_PROCESS);

%let period=Weekly;
%include source(WEEKLY_PROCESS);

%let period=Monthly;
%include source(MONTHLY_PROCESS);

%if %eval(day("&t_day"+1)) = 1 %then %do;

%let period=Quarterly;
%include source(QUARTERLY_PROCESS);

%let period=Yearly;
%include source(YEARLY_PROCESS);



But I get an error on the %if statement- I can't use it 'in open code'. (Value of &t_day is yesterday).

I'm sure you can see what it is that I am trying to do here. This is the entire program - there are no DATA steps until the process code is included.

Thanks in advance.
Posts: 8,742

Re: Conditional Processing With Macro Vars

%IF and macro conditional logic can only be used in a SAS Macro definition -- also sometimes called a SAS Macro program. A SAS Macro definition is like this:
%macro mymacpgm(parm1=, parm2=);
....some code including %IF, %DO, etc other code, datastep code, proc code, etc....
%mend mymacpgm;

Now, to invoke the macro definition, you must do:
%mymacpgm(parm1=wombat, parm2=koala)

This is a very good introduction to the Macro Facility, which will take you through the basics and explain why you can't use %IF in open code:

Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation