BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
edge900rr
Calcite | Level 5

I have the following let statements that are causing an error 22-322: 

 

%let Excel_Sheet_Name = cat("'",&Fleet_Type, " P/N 12 MOnth Rolling'");
%let Excel_File_Name = cat("'",&Fleet_Type, " MTBR.xml'");

 

44 ods tagsets.excelxp path='\\Cmhprdfps22\data\MAINTENANCE\Reliability\Program Analyst Data\Dave P\SAS AutoBatch Exports\'
45 file=&Excel_File_Name
46 style=Grayscaleprinter;
NOTE: Line generated by the macro variable "EXCEL_FILE_NAME".
46 cat("'","CE-560XL", " MTBR.xml'")
2 The SAS System 10:54 Tuesday, August 21, 2018

___
22
76
ERROR 22-322: Syntax error, expecting one of the following: DYNAMIC, NO_BOTTOM_MATTER, NO_TOP_MATTER, TITLE, URL.
ERROR 76-322: Syntax error, statement will be ignored.
47
48 ods tagsets.ExcelXP options(sheet_label=' ' sheet_name=&Excel_Sheet_Name autofilter='yes');
NOTE: Line generated by the macro variable "EXCEL_SHEET_NAME".
48 cat("'","CE-560XL", " P/N 12 MOnth Rolling'")
___
22
202
ERROR 22-322: Expecting a quoted string.
ERROR 202-322: The option or parameter is not recognized and will be ignored.

 

thanks for the help.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Macro language does not typically use CAT to combine strings.  In fact, if you want to use CAT in macro language, you need to enclose it within %SYSFUNC.  Easier to read (once you are used to it), and able to overcome the need to resolve a macro variable in single quotes, might be:

 

%let Excel_Sheet_Name = %unquote(%str(%'&Fleet_Type P/N 12 MOnth Rolling%'));

 

Within %STR, refer to single quotes with a percent sign:  %'

View solution in original post

4 REPLIES 4
Astounding
PROC Star

Macro language does not typically use CAT to combine strings.  In fact, if you want to use CAT in macro language, you need to enclose it within %SYSFUNC.  Easier to read (once you are used to it), and able to overcome the need to resolve a macro variable in single quotes, might be:

 

%let Excel_Sheet_Name = %unquote(%str(%'&Fleet_Type P/N 12 MOnth Rolling%'));

 

Within %STR, refer to single quotes with a percent sign:  %'

edge900rr
Calcite | Level 5

Sweet.  Thanks!!!

error_prone
Barite | Level 11
Cat is a data-step function, if you want to use it in a %let statement you have to wrap it in %sysfunc. If you want to concatenate strings in macro code you don't have to use cat at all. And, please avoid quotes in macro variables, add them when using the variable. Try:

%let Excel_Sheet_Name = &Fleet_Type. P/N 12 Month Rolling;
%let Excel_File_Name = &Fleet_Type. MTBR.xml;

And later: file= "&Excel_File_Name."
Same for the sheet-name option.
Kurt_Bremser
Super User

After the macro variable is resolved, you get this:

file=cat("'",&Fleet_Type, " P/N 12 MOnth Rolling'")

which is obviously invalid.

To use a data step function in a %let, you need to use %sysfunc. Also note that concatenation in macro is done simply by writing text in sequence:

&fleet_type._rest_of_the_filename

Also note that blanks in filenames are bad. Use underlines instead.

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
  • 1776 views
  • 0 likes
  • 4 in conversation