DATA Step, Macro, Functions and more

execute sas program using a sas program

Reply
Contributor
Posts: 37

execute sas program using a sas program

Is there a was to execute a sas program from another sas program.

example:
retreivedata.sas creates a table from various sources.

myfile = sas_code\retreivedata.sas

data result;
set myfile;

if cat in ('specialty', 'lines') then cat = 'other';
run;
Super Contributor
Super Contributor
Posts: 365

Re: execute sas program using a sas program

Hello Mick_g,

I did not get your point. If your "retreivedata.sas creates a table" then you simply use this name in the following datastep:
[pre]
data result;
set TableName;
if cat in ('specialty', 'lines') then cat = 'other';
run;
[/pre]
Sincerely,
SPR
Super Contributor
Super Contributor
Posts: 3,174

Re: execute sas program using a sas program

With SAS system, you have some options like using a SAS view to generate a file and then reference the file in a subsequent DATA step, for example.

Also, if you use the SET statement and supply no specific input, SAS will default to the prior SAS member/file created in the same SAS session.

Also, if you wish to specify a SAS file to create and then in a subsequent input using a SET, then consider using a SAS MACRO variable to list the "passed" file name information, where it would be defined with a %LET statement, referenced on a DATA statement using the associated macro variable syntax, and then again later referenced, as needed, again with the macro variable syntax.

Otherwise, it's not really clear exactly what you are trying to accomplish and how to recommend an approach, without more specific detailed information.

Scott Barry
SBBWorks, Inc.
Valued Guide
Posts: 2,175

Re: execute sas program using a sas program

Interesting number of alternative interpretations of this question!
To add to the variety, I had assumed the names of the programs to be executed were in a variable of a metadata table. Then
CALL EXECUTE( '%include ' !! Quote( Cats( path, ProgName )) !! " ;" );
might do what is needed.

Peter
Contributor
Posts: 37

Re: execute sas program using a sas program

I actually work the problem out a different way. I have three different programs that rely on the output of the the previous program.
so what I was trying to do is have the first programs executed the code from another programs to create a table in current program then send the results to another program for execution

here is how i fixed; in the first program i had an include statement to get code from another program in the second program I have an include first program in the third program i included code again from another program and include second program and I am now working witht the data.

I think there is an easier way but this works for now so thanks for the help
Super User
Posts: 10,538

Re: execute sas program using a sas program

If it is code used frequently it might be worth making it a macro and placing it in an AUTOCALL library.
Ask a Question
Discussion stats
  • 5 replies
  • 163 views
  • 0 likes
  • 5 in conversation