DATA Step, Macro, Functions and more

Using program name as ods rtf file name

Accepted Solution Solved
Reply
Contributor
Posts: 26
Accepted Solution

Using program name as ods rtf file name

Hello, 

 

I use this program to obtain path and file name:

 

%let execpath=" ";

%macro setexecpath;
%let execpath=%sysfunc(GetOption(SYSIN));
%if %length(&execpath)=0
%then %let execpath=%sysget(SAS_EXECFILEPATH);
%mend setexecpath;

%setexecpath;
%put &execpath;

 

The result is something like this: 

XX$XX:[XX.myfolder.program]program_name.SAS

 

I just want to use a portion of the result like 'program_name' instead of typing the program name as a rtf file name each time. 

 

I tried this, thinking that I would have a long file name: 

ods rtf file="%sysfunc(getoption(SYSIN)).rtf";

 

But, I got an error message: 

ERROR: Invalid open mod

 

I do not need the full information to start with, but could anybody tell me what I should write after 'ods rtf file=' to get just a program_name? 

 

Thank you, 

 

Yoko

 


Accepted Solutions
Solution
‎11-03-2017 12:10 PM
Super User
Super User
Posts: 9,840

Re: Using program name as ods rtf file name

I really don't think that is your best option, the code will not work if run in batch for instance.  However you could change your code to make it work for now:

data _null_;
  tmp="%sysfunc(GetOption(SYSIN))";
  call symput('fname',scan(tmp,2,"]"));
run;

ods rtf file="&fname.";
...

What I am doing here is putting the macro data into a datastep and using nice simple base SAS commands to process the data (for that is what Base SAS is for) to process the string, pull out the bit I want and then send back to macro.

View solution in original post


All Replies
Solution
‎11-03-2017 12:10 PM
Super User
Super User
Posts: 9,840

Re: Using program name as ods rtf file name

I really don't think that is your best option, the code will not work if run in batch for instance.  However you could change your code to make it work for now:

data _null_;
  tmp="%sysfunc(GetOption(SYSIN))";
  call symput('fname',scan(tmp,2,"]"));
run;

ods rtf file="&fname.";
...

What I am doing here is putting the macro data into a datastep and using nice simple base SAS commands to process the data (for that is what Base SAS is for) to process the string, pull out the bit I want and then send back to macro.

Contributor
Posts: 26

Re: Using program name as ods rtf file name

Thank you, it worked!

 

Yoko

Super User
Posts: 13,941

Re: Using program name as ods rtf file name

Are you working on a windows system, using the Enhanced editor (which implies running in Display Manager)?

If not the SAS_EXECFILEPATH isn't available.

If you are the value isn't set until after you save the program file.

 

And to get just the path if the above conditions are met (and assuming you don't put periods in the middle of your paths, of so...)

 

%let execpath= %scan(%sysget(SAS_EXECFILEPATH),1,.);

%put &execpath; (if you want to see the resolved version)

 

ods rtf file="&execpath..rtf"; should then work.

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 139 views
  • 0 likes
  • 3 in conversation