DATA Step, Macro, Functions and more

Conditional Processing With Macro Vars

Reply
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:

[pre]

%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);

%end;

[/pre]

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.
SAS Super FREQ
Posts: 8,864

Re: Conditional Processing With Macro Vars

Hi:
%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:
[pre]
%macro mymacpgm(parm1=, parm2=);
....some code including %IF, %DO, etc other code, datastep code, proc code, etc....
%mend mymacpgm;
[/pre]

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

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:
http://www2.sas.com/proceedings/sugi28/056-28.pdf

cynthia
Ask a Question
Discussion stats
  • 1 reply
  • 244 views
  • 0 likes
  • 2 in conversation