BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Yoko
Obsidian | Level 7

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Yoko
Obsidian | Level 7

Thank you, it worked!

 

Yoko

ballardw
Super User

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.

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3 replies
  • 887 views
  • 0 likes
  • 3 in conversation