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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 1 reply
  • 1831 views
  • 0 likes
  • 2 in conversation