BookmarkSubscribeRSS Feed
Babloo
Barite | Level 11

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 &parameter_1 IN("&parameter_2");
var &_field;
run;

data _null_;
test = '/'||&parameter_2||'/';
put test=;
run;

Log:

12   proc print data=sorted_nodup noobs;
13   where &parameter_1 IN("&parameter_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 = '/'||&parameter_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;

 

 

4 REPLIES 4
PeterClemmensen
Super User

Put double quotes around the macro variable.

 

%let parameter_2 = Data Management;

data _null_;
test = '/'||"&parameter_2"||'/';
put test=;
run;
Babloo
Barite | Level 11
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
PaigeMiller
Diamond | Level 26

@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 = '/'||"&parameter2"||'/';
put test=;
run;

 

 

Show us how you create this macro variable. Show us what you are doing after it is created.

--
Paige Miller
PaigeMiller
Diamond | Level 26

The log shows clearly that the macro variable is indeed resolving properly.

 

17   data _null_;
18   test = '/'||&parameter_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.

--
Paige Miller

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 128 views
  • 0 likes
  • 3 in conversation