Help using Base SAS procedures

Calling SAS code from another SAS program including passing variables?

Reply
Regular Contributor
Posts: 177

Calling SAS code from another SAS program including passing variables?

Hello

 

I am using SAS 9.4.

 

I have a program called "regroup" that indicates the location of two sets of text documents plus an export file name as %let export_file:

Libname mylib 'C:\SAS Datasets';
filename M_regrp('C:\text data\monthly\.*txt';
filename Y_regrp('C:\text data\yearly\*.txt';
%let export_file="C:\sas_data.mdb";

I wish to call the regroup from another program and pass the 4 settings above from the other program.  How do I do that?  Thanks.

 

Super User
Posts: 10,280

Re: Calling SAS code from another SAS program including passing variables?

Why would you handle something simple as that in an external include? It only obfuscates your code and makes life a misery for your future self.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Regular Contributor
Posts: 177

Re: Calling SAS code from another SAS program including passing variables?

Posted in reply to KurtBremser

The report in question (regrp) is actually used for many hospitals and I have them all in the code and just comment out the sites I don't want at the time I run it.  So rather than have multiple copies of regrp to call for each site from this other program, I thought it would be easier to call it from another program that I have to run that uses the resulting dataset from the regrp program.

Super User
Posts: 10,280

Re: Calling SAS code from another SAS program including passing variables?

And what about those 4 statements should be parameterized?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Regular Contributor
Posts: 177

Re: Calling SAS code from another SAS program including passing variables?

Posted in reply to KurtBremser

Not sure I know what you're asking but each hospital with have a different location for the file location of M_regrp and Y_regrp as well as different locations for the library name and the export_file.  So I want to pass those to the report via the other report that calls the program.  

Super User
Posts: 10,280

Re: Calling SAS code from another SAS program including passing variables?

Define what the "settings" are in this sentence from your first post:

 

I wish to call the regroup from another program and pass the 4 settings above from the other program.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Regular Contributor
Posts: 177

Re: Calling SAS code from another SAS program including passing variables?

Posted in reply to KurtBremser
The other program imports data from two locations and merges them, exports to a database and is saved to a specific library.

So I assume I would use %include to indicate the program I want to run, but I want to know how to identify the location of M_regrp and Y_regrp files, the library name to save the dataset to and the database to export the table to. Those are the settings being passed to the called report.
Super User
Posts: 10,280

Re: Calling SAS code from another SAS program including passing variables?

So you would do something like

%let libpath=C:\SAS Datasets;

%include 'c:\.......\regroup.sas';

and regroup.sas would be

libname mylib "&libpath.";
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Regular Contributor
Posts: 177

Re: Calling SAS code from another SAS program including passing variables?

Posted in reply to KurtBremser

 

I wasn't sure about what you were advising but I found that all I needed to do was to copy the filename, libname and let statement for the database to above the %include line and it runs as it should.  Thanks.

 

Super User
Posts: 10,787

Re: Calling SAS code from another SAS program including passing variables?

If you have SAS/IML, you could try CALL EXECUTEFILE() .

Ask a Question
Discussion stats
  • 9 replies
  • 113 views
  • 0 likes
  • 3 in conversation