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
SAS Super FREQ
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

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!

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.

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
  • 849 views
  • 0 likes
  • 2 in conversation