BookmarkSubscribeRSS Feed
stan
Quartz | Level 8

Hey folks,

when I try to name a new .rtf file with the following code:

%let my_folder = my_example_directory;

%let my_lastname = my_file.txt;

%let MyExttPic = .rtf

/*transtrn() searches for .txt and replaces it for a space*/

/*compress() removes the space*/

%let myfilename = compress(transtrn("&my_folder.\&lastname._pics&MyExttPic", ".txt", ""));

ODS RTF FILE = &myfilename;

<...>

ODS RTF CLOSE;

the errors show up in Log:

ERROR 22-322: Syntax error, expecting one of the following: ;, '.', ANCHOR, AUTHOR, BASE, BODY, BOOKMARK,

              CHARSET, CLOSE, COLUMNS, CONTENTS, CSSSTYLE, DATAPANEL, ENCODING, FILE, FONTSCALE,

              GFOOTNOTE, GTITLE, HOST, IMAGE_DPI, KEEPN, LSTPIPE, NEWFILE, NOCONTENTS, NOGFOOTNOTE,

              NOGTITLE, NOKEEPN, NOLSTPIPE, NOOUTLINE, OPERATOR, OUTLINE, PACKAGE, PATH, RECORD_SEPARATOR,

              SAS, SGE, STARTPAGE, STYLE, TEXT, TITLE, TRANTAB.

ERROR 200-322: The symbol is not recognized and will be ignored.

In short I'd like to get rid of ".txt" in my .rtf file name. So I've decided to use the functions and %let-& bundle.

I suspect their position are incorrect. But how to manage the issue?

Any ideas on errors?

Thank you.

1 REPLY 1
Tom
Super User Tom
Super User

Use %SYSFUNC().  Also watch your semi-colons and do not use quotes around strings in macro code, unless the quotes are part of the string.

%let my_folder = my_example_directory;

%let my_lastname = my_file.txt;

%let MyExttPic = .rtf ;

%let myfilename = &my_folder/%sysfunc(tranwrd(&my_lastname,.txt,&myexttpic));

%put myfilename=&myfilename;

myfilename=my_example_directory/my_file.rtf

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 2294 views
  • 0 likes
  • 2 in conversation