Hi ,
Is there any way i can call macro variable demvar inside the key word macro .
Here is my code and when i am trying to run it I am getting the error :ERROR: More positional parameters found than defined."
%let demvar= x , y, z;
%put &demvar;
%macro table(indata, outdata, varlist );
Proc sql;
create table &outdata. as
select &varlist.
from &indata.
where patid in (select patid from ca)
order by patid;
quit;
%mend;
%table(a, b , (%str(&demvar));
My purpose of doing so is to create multiple dataset by changing name of variable of interest in demvar.
Thanks,
Jeetender
@jeetendersinghc wrote:
Hi ,
Is there any way i can call macro variable demvar inside the key word macro .
Here is my code and when i am trying to run it I am getting the error :ERROR: More positional parameters found than defined."%let demvar= x , y, z; %put &demvar; %macro table(indata, outdata, varlist ); Proc sql; create table &outdata. as select &varlist. from &indata. where patid in (select patid from ca) order by patid; quit; %mend; %table(a, b , (%str(&demvar));
My purpose of doing so is to create multiple dataset by changing name of variable of interest in demvar.
Thanks,
Jeetender
Try
%table(a,b,%quote(&demvar))
Generally speaking, you want to put the %quote function around a macro variable if it might contain special characters like the comma. In this situation, %str() doesn't help. You would use %str() when you are creating a string and you actually have to type the comma character (or other special character) and not have the comma be treated as having a special meaning like a delimiter, it then gets treated as plain text. Example:
%table(a,b,%str(x,y,z))
@jeetendersinghc wrote:
Hi ,
Is there any way i can call macro variable demvar inside the key word macro .
Here is my code and when i am trying to run it I am getting the error :ERROR: More positional parameters found than defined."%let demvar= x , y, z; %put &demvar; %macro table(indata, outdata, varlist ); Proc sql; create table &outdata. as select &varlist. from &indata. where patid in (select patid from ca) order by patid; quit; %mend; %table(a, b , (%str(&demvar));
My purpose of doing so is to create multiple dataset by changing name of variable of interest in demvar.
Thanks,
Jeetender
Try
%table(a,b,%quote(&demvar))
Generally speaking, you want to put the %quote function around a macro variable if it might contain special characters like the comma. In this situation, %str() doesn't help. You would use %str() when you are creating a string and you actually have to type the comma character (or other special character) and not have the comma be treated as having a special meaning like a delimiter, it then gets treated as plain text. Example:
%table(a,b,%str(x,y,z))
Thank's Paige. After using %bquote its working now and thanks a lot for clarifying the difference between %quote and %str.
Regards,
Jeetender
i removed the comma's and still getting the error but this time "
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, !, !!, &, (, *,
**, +, ',', -, '.', /, <, <=, <>, =, >, >=, ?, AND, AS, BETWEEN, CONTAINS, EQ,
EQT, FORMAT, FROM, GE, GET, GT, GTT, IN, INFORMAT, INTO, IS, LABEL, LE, LEN,
LENGTH, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, TRANSCODE, ^, ^=, |, ||,
~, ~=.
ERROR 76-322: Syntax error, statement will be ignored.
"
The value which i have mentioned in demvar are the list of variables which i need to keep in my table. so by removing the commas from these values seems wouldn't work.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.