BookmarkSubscribeRSS Feed
OS2Rules
Obsidian | Level 7
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.
1 REPLY 1
Cynthia_sas
Diamond | Level 26
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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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