BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BrahmanandaRao
Lapis Lazuli | Level 10
%macro t1(a,b,c);
data &a;
set &a	;
where Type eq (&c and Origin &c);
run;
%mend t1;

%t1(dsn,sashelp.cars,	'Sedan' & 'Asia');

why error please advise me 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Rule #1 of macro development: start with working SAS code.

By manually resolving your macro parameters, I get this code:

data dsn;
set dsn;
where Type eq ('Sedan' & 'Asia' and Origin 'Sedan' & 'Asia');
run;

The where condition is very obviously invalid syntax. Fix that in the data step code, and then start to make it dynamic by proper use of macro variables.

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

Rule #1 of macro development: start with working SAS code.

By manually resolving your macro parameters, I get this code:

data dsn;
set dsn;
where Type eq ('Sedan' & 'Asia' and Origin 'Sedan' & 'Asia');
run;

The where condition is very obviously invalid syntax. Fix that in the data step code, and then start to make it dynamic by proper use of macro variables.

PaigeMiller
Diamond | Level 26

Agreeing with @Kurt_Bremser , you have to create working SAS code without macro variables first. If your code doesn't work properly without macro variables, then it will not work properly with macro variables.

 

Also, you rarely need to have the values of macro variables enclosed in quotes.

--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 852 views
  • 1 like
  • 3 in conversation