DATA Step, Macro, Functions and more

Compress and transtrn SAS functions: how to couple them with macro?

Reply
Contributor
Posts: 57

Compress and transtrn SAS functions: how to couple them with macro?

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.

Super User
Super User
Posts: 6,502

Re: Compress and transtrn SAS functions: how to couple them with macro?

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

Ask a Question
Discussion stats
  • 1 reply
  • 1006 views
  • 0 likes
  • 2 in conversation