DATA Step, Macro, Functions and more

SAS macro

Posts: 30

SAS macro

Hi Team,


I am trying to run the below macro code and it gives an error.


I couldnt figure out the error. Could you please help me


%macro roster;

proc sql;

create table NON_RESPONDERS_BULLET_7_P as

select t1.* from DSS_HRA_Healthfirst_Roster t1

where (t1.EFFECTIVE_DATE < intnx('year',today(),-1,'S') OR t1.EFFECTIVE_DATE > intnx('year',today(),-1,'E'))


and ((t1.LAST_SURVEY_DATE1 BETWEEN intnx('year',&start3mnth,-15) and intnx('year',&end3month,-15))

%do i = -14 %to -2;

or (t1.LAST_SURVEY_DATE1 BETWEEN intnx('year',&start3mnth,&i) and intnx('year',&end3month,&i))


or (t1.LAST_SURVEY_DATE1 BETWEEN intnx('year',&start3mnth,&i) and intnx('year',&end3month,&i)));


%mend roster;


 ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, ',', -, /, <,
              <=, <>, =, >, >=, ?, AND, CONTAINS, EQ, EQT, GE, GET, GT, GTT, LE, LET, LIKE,
              LT, LTT, NE, NET, OR, ^=, |, ||, ~=.



Posts: 1,233

Re: SAS macro

What are the values of &start3mnth and &end3month?

Posts: 30

Re: SAS macro

Hi Quentin,


%put &end3month &start3mnth ;

/* 31AUG2015 01AUG2015 */


Super User
Posts: 17,861

Re: SAS macro

Looking at a single line of code and what it would resolve to. This isn't valid SAS code. 


and ((t1.LAST_SURVEY_DATE1 BETWEEN intnx('year',&start3mnth,-15) and 
and ((t1.LAST_SURVEY_DATE1 BETWEEN intnx('year',01AUG2015,-15) and 


You need to provide those as date literals to the macro 




Change your code to allow your dates to resolve properly.  

Super User
Posts: 10,516

Re: SAS macro

If you run the macro with the option mprint the error will appear in the log in a more useful location;


options mprint;



Without data or values for your macro variables Start3Mnt and End3Month it's a bit hard to be more precise though if either of those is blank that could be a cause.

Super User
Super User
Posts: 7,407

Re: SAS macro

What is it your trying to do.  Post test data in the form of a datastep and what the output should look like.  That block of code firstly doesn't need to be in a macro - all your seem to be doing is taking data where last_survey_date is between some set of months on 14 years to 2 years before.  This is simple logic and doesn't need 14 "or" clauses generated for it.  A simple datastep will also make life easier for you, but I can't post example code until you show your data and what its suppoed to look like.

Ask a Question
Discussion stats
  • 5 replies
  • 5 in conversation