BookmarkSubscribeRSS Feed
Babloo
Rhodochrosite | Level 12

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
Tourmaline | Level 20

Put double quotes around the macro variable.

 

%let parameter_2 = Data Management;

data _null_;
test = '/'||"&parameter_2"||'/';
put test=;
run;
Babloo
Rhodochrosite | Level 12
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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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