If the value of the macro variable have spaces then the following code is throwing the syntax error. Code and log is shown below. Any help to resolve the issue?
Value of macro variable 'parameter_2' resolves to 'Data Management'
Program:
proc print data=sorted_nodup noobs; where ¶meter_1 IN("¶meter_2"); var &_field; run; data _null_; test = '/'||¶meter_2||'/'; put test=; run;
Log:
12 proc print data=sorted_nodup noobs; 13 where ¶meter_1 IN("¶meter_2"); 14 var &_field; 15 run; NOTE: There were 194 observations read from the data set WORK.SORTED_NODUP. WHERE DIVISION='Data Management'; NOTE: PROCEDURE PRINT used (Total process time): real time 0.01 seconds cpu time 0.01 seconds 16 17 data _null_; 18 test = '/'||¶meter_2||'/'; NOTE: Line generated by the macro variable "PARAMETER_2". 18 Data Management ---------- 22 ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, -, /, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT, LE, LT, MAX, MIN, NE, NG, NL, OR, [, ^=, {, |, ||, ~=. 19 put test=; 20 run;
Put double quotes around the macro variable.
%let parameter_2 = Data Management;
data _null_;
test = '/'||"¶meter_2"||'/';
put test=;
run;
@Babloo wrote:
How to handle this macro variable when it is separated by commas. E.g. Data
Management, Data Analytics.
Sometimes it will resolve with Data Management and sometimes with Data
Management, Data Analytics
I don't see why this creates a problem, unless you are doing something different than what you showed above. The following code works fine:
%let parameter2=Data Management, Data Analytics;
%put &=parameter2;
data _null_;
test = '/'||"¶meter2"||'/';
put test=;
run;
Show us how you create this macro variable. Show us what you are doing after it is created.
The log shows clearly that the macro variable is indeed resolving properly.
17 data _null_; 18 test = '/'||¶meter_2||'/'; NOTE: Line generated by the macro variable "PARAMETER_2". 18 Data Management ---------- 22 ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, -, /, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT, LE, LT, MAX, MIN, NE, NG, NL, OR, [, ^=, {, |, ||, ~=. 19 put test=; 20 run;
It is using the proper value of the macro variable, specifically Data Management, when it creates the code.
The problem is that the macro is not creating valid legal working code in SAS, that's why you see the ERROR. The code your usage of this macro is creating is this:
data _null_;
test = '/'||Data Management||'/';
put test=;
run;
Can you see where the error is? Can you see why this code does not work? Please fix it, first without macros, just get those four lines directly above to work.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.