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.
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.