Folder path from %include statement

Reply
Contributor
Posts: 20

Folder path from %include statement

I want to find folder name (FIGURE, LISTING, TABLE) from following code. I know that it is possible to get by using FILENAME statement but from INCLUDE statement can we get it?

 

%inc "H:\Analysis\Program\Figure\f_vs03.sas";
%inc "H:\Analysis\Program\Listing\l_ae01.sas";
%inc "H:\Analysis\Program\Table\t_dm01.sas";

I also know when we run interactively one by one then we can get it through SAS_EXECFILEPATH.

 

My objective is to find folder name becuase it is referenced to one of the macro but i need to find automatically to redirect log and output as batch program using INC statement not SYSTASK or X Command

Super User
Posts: 5,255

Re: Folder path from %include statement

[ Edited ]

Not knowing much of your application. But I would like to go from the direction: what program do I like to execute?

Then I would register that in some kind of metadata table, or macro variable. Then I would do the execution (in your case, by %INCLUDE).

Does this makes sense?

Or, how does your application setup look like?

Data never sleeps
Contributor
Posts: 20

Re: Folder path from %include statement

within each program standard macros are there. if we run program individually that is fine. One of the standard macro has the following code. %scan(%sysget(sas_execfilepath),-2,\) has folder name. When we call using INC statement it is taking the path where batch program is saved instead of original program

 

%let goutfiln=&goutpath\%scan(%sysget(sas_execfilepath),-2,\)\&goutfnm..&lfileext;

 

 

Super User
Super User
Posts: 7,392

Re: Folder path from %include statement

Personally I believe you are doing it the wrong way round.  I would suggest that a robust system would be setup where these things are inferred eitehr in a setup program, or by metadata you provide up front.  An example of this would be a start program which creates a libname to each of the working areas, then include would be:

%include "%sysfunc(pathname(location))\File_to_include.sas";

 

That way you can always pull the pathname from a library out easily.  Alternatively, that metadata could come from a main run program or some other method.  Ultimately its easier to know what goes into your code, rather than at the end try to extract it, i.e. planning is more important than running.  Of course, you would be following SDLC, so you would have your program plan, and know what elements combine to make the following code...

Contributor
Posts: 20

Re: Folder path from %include statement

Thanks RW9. Hope you didnt understand my question correctly. It is almost similar to your question URL:
https://communities.sas.com/t5/General-SAS-Programming/include-path/td-p/152600
Super User
Super User
Posts: 7,392

Re: Folder path from %include statement

Indeed, that post was my last attempt to find a workable solution within SAS.  Now, I would recommend a utility which can launch batch SAS, and that utility would handle all metedata.  The whole metadata structure could do with an overhaul really.

Super User
Posts: 5,076

Re: Folder path from %include statement

Here's a simple approach.  Replace the %include statements with a macro call:

 

%macro go_get (full_path);

   %inc "&full_path";

%mend goget;

 

Then later instead of %inc:

 

%go_get (H:\Analysis\Program\Figure\f_vs03.sas)

 

Now the macro can be expanded to pull out the folder name and process it any way you would like.

Ask a Question
Discussion stats
  • 6 replies
  • 381 views
  • 0 likes
  • 4 in conversation