f



Possible to run a SAS program within another SAS program?

Hello, I have 9 SAS programs, all within the same Windows folder that I
usually run at the same time - one right after the other. For
convenience, is it possible to write a simple SAS program that will let
me run all the programs at once or to have a program that will allow me
to pick and choose which SAS programs I want to run (e.g., in the case
I only want to run the first 3 and last program out of the 9 SAS
programs) and which order the programs are run in? I guess what I'm
really looking for is if there is a way to call another SAS program
using only a couple lines of code so that, if I choose not run that
program, I can just comment that code out or something like that. Let
me know if this is possible, thanks!!!

Julie

0
12/7/2005 7:28:43 PM
comp.soft-sys.sas 142828 articles. 3 followers. Post Follow

9 Replies
694 Views

Similar Articles

[PageSpeed] 41

You could use the %include statement to call a specified program.
for example :

%include "c:\documents and settings\nkrishna\my
documents\macros\upcase_mac.sas";

where upcase_mac.sas is a program stored in the above path..so you
could write an include statement for each program and then copy and
paste them into any order you need..unless of course i am
misunderstanding your needs..:-)

--nevin

0
12/7/2005 7:42:28 PM
No, I think your suggestion is exactly what I was looking for,
thanks!!!

Julie

0
12/7/2005 7:48:04 PM
oseithedude@gmail.com wrote:
> Hello, I have 9 SAS programs, all within the same Windows folder that
> I usually run at the same time - one right after the other. For
> convenience, is it possible to write a simple SAS program that will
> let me run all the programs at once or to have a program that will
> allow me to pick and choose which SAS programs I want to run (e.g.,
> in the case I only want to run the first 3 and last program out of
> the 9 SAS programs) and which order the programs are run in? I guess
> what I'm really looking for is if there is a way to call another SAS
> program using only a couple lines of code so that, if I choose not
> run that program, I can just comment that code out or something like
> that. Let me know if this is possible, thanks!!!
>
> Julie

This is an excellent scenario for a SAS/AF frame.

Supposing you don't have AF:
The File/Open dialog has a Submit checkbox.  When checked and you select
_more than one_ file in the file dialog, each file will be submitted in
sequence.  The only caveat is that the order submitted is reverse of as show
in the file dialog Filename field.  E.g.
"a.sas" "b.sas" "c.sas" will cause the submittal of C then B then A.

The same sort of issue occurs when multiple files are selected in straight
up Windows Explorer (which the File.Open dialog utilizes).  Basically, a
Windows LIFO stack of file selections is causing the reversal.

An alternative would be to write a program that writes a program that
contains only include statements based on a directory listing.

generate this code from input of filename listing PIPE "DIR /B *.sas"
/** / %include "A.sas"; /**/
/** / %include "B.sas"; /**/
/** / %include "C.sas"; /**/

Note the space in the leading 'almost' comment block.  Since there is a
space, the comment extends to the trailing comment block which closes the
leading 'almost'.

To run a select series of programs, simply remove the space from the leading
almost comment block from which ever programs you want to run.

Run A and C.
/**/ %include "A.sas"; /**/
/** / %include "B.sas"; /**/
/**/ %include "C.sas"; /**/

IIRC, this style of commenting, for easy on/off of code blocks, was made
popular by Ron Fehd.

-- 
Richard A. DeVenezia
http://www.devenezia.com/


0
rdevenezia1 (1435)
12/7/2005 7:50:04 PM
Julie,

Uhhh create a macro that simply %includes the programs you want and in what
order.  It would be very specific to you the creator and user, in other
words right biw I can't think of a good way to pass al the info you need to
the macro from the user.  As you can tell the user interface would be the
crucial part of this.

I personally wouldnt want to have this in my production code but have
written SAS programs that do nothing more than %include a list of programs.



Toby Dunn





From: oseithedude@GMAIL.COM
Reply-To: oseithedude@GMAIL.COM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Possible to run a SAS program within another SAS program?
Date: Wed, 7 Dec 2005 11:28:43 -0800
Hello, I have 9 SAS programs, all within the same Windows folder that I
usually run at the same time - one right after the other. For
convenience, is it possible to write a simple SAS program that will let
me run all the programs at once or to have a program that will allow me
to pick and choose which SAS programs I want to run (e.g., in the case
I only want to run the first 3 and last program out of the 9 SAS
programs) and which order the programs are run in? I guess what I'm
really looking for is if there is a way to call another SAS program
using only a couple lines of code so that, if I choose not run that
program, I can just comment that code out or something like that. Let
me know if this is possible, thanks!!!

Julie
0
tobydunn (6020)
12/7/2005 8:03:47 PM
It can be as simple as the following, it will execute either of the sas
program depending upon the value of runit.

HTH

%let runit=1;

data _null_;
  *put your derive logic here;
  if "&runit"=1 then call execute ('%include "c:\temp\test1.sas";' );
  else if "&runit"=2 then call execute ('%include "c:\temp\test2.sas";'
);
run;

0
shiling99 (640)
12/7/2005 8:42:58 PM
Sorry. Need a quote on 1 and 2.

0
shiling99 (640)
12/7/2005 9:05:40 PM
<oseithedude@gmail.com> wrote in message
news:1133983723.040049.182910@g47g2000cwa.googlegroups.com...
> Hello, I have 9 SAS programs, all within the same Windows folder that I
> usually run at the same time - one right after the other. For
> convenience, is it possible to write a simple SAS program that will let
> me run all the programs at once or to have a program that will allow me
> to pick and choose which SAS programs I want to run (e.g., in the case
> I only want to run the first 3 and last program out of the 9 SAS
> programs) and which order the programs are run in? I guess what I'm
> really looking for is if there is a way to call another SAS program
> using only a couple lines of code so that, if I choose not run that
> program, I can just comment that code out or something like that. Let
> me know if this is possible, thanks!!!
>
> Julie
>
So which is it - "all at the same time" or "one right after the other"?

What I mean by that is, do the programs have to run in a particular
sequence, or can they run in any order?  Do they access the same
files/datasets?

If they can run in any order and they don't use the same inputs/outputs - in
other words, if the programs are independent - the easiest way to run a
bunch of them "at the same time" is to take advantage of Windows.

Open a window on the directory that contains the programs (you can use "My
Computer" or Windows Explorer)
Highlight the programs you want to run (click on the first program file in
the list, hold down the shift key and click on the last program file)
RIGHT click anywhere on the highlighted list of program files
Click on "Batch Submit" in the pop-up menu


0
12/8/2005 2:46:01 AM
nevin.krishna@gmail.com wrote:
> You could use the %include statement to call a specified program.
> for example :
>
> %include "c:\documents and settings\nkrishna\my
> documents\macros\upcase_mac.sas";
>
> where upcase_mac.sas is a program stored in the above path..so you
> could write an include statement for each program and then copy and
> paste them into any order you need..unless of course i am
> misunderstanding your needs..:-)
>
> --nevin

Thanks for all the responses! I have another questions though... in 4
or 5 of the SAS programs, there is a simple macro statement that helps
indicate the version of the end dataset that is created. They all have
a %let version = A statement, for example, at the beginning of the
program... the macro variable is tacked on to the end of the dataset
name to let me know that this is version "A" of the dataset. Each time
I run the programs, I change the version letter within the programs
(e.g., to "B" or "C")... if I create a separate SAS program using
%include to run all of these programs, could I also set the version
macro variable to whatever letter I want within this same program or is
this not possible?

Julie

0
12/8/2005 6:32:49 AM
oseithedude@gmail.com wrote:
> nevin.krishna@gmail.com wrote:
>> You could use the %include statement to call a specified program.
>> for example :
>>
>> %include "c:\documents and settings\nkrishna\my
>> documents\macros\upcase_mac.sas";
>>
>> where upcase_mac.sas is a program stored in the above path..so you
>> could write an include statement for each program and then copy and
>> paste them into any order you need..unless of course i am
>> misunderstanding your needs..:-)
>>
>> --nevin
>
> Thanks for all the responses! I have another questions though... in 4
> or 5 of the SAS programs, there is a simple macro statement that helps
> indicate the version of the end dataset that is created. They all have
> a %let version = A statement, for example, at the beginning of the
> program... the macro variable is tacked on to the end of the dataset
> name to let me know that this is version "A" of the dataset. Each time
> I run the programs, I change the version letter within the programs
> (e.g., to "B" or "C")... if I create a separate SAS program using
> %include to run all of these programs, could I also set the version
> macro variable to whatever letter I want within this same program or
> is this not possible?
>
> Julie

Now you are getting into some interesting scenarios.

Since the LET is hardcoded into the top of the program, there is nothing you
can do before running the program to change that.

P1.sas
-----
%let version = A;
%put version = &version;
.....
-----

%let version = B;
%include "P1.sas";

During the running of P1, version will always be A.


Any options? Sure.
1. Edit the 4 of 5 sas programs to _not_ have a LET at the top.  Instead put
a comment stating the value of macro variable VERSION must be pre-assigned
prior to running the program.

2. Encapsulate the entire program in a macro.  Pass the version value in the
macro invocation.  Place the macros in your sasautos path.  This is only
sensible if you have the time and resources to modularize the 'dispatch' of
several programs.  It begins to be justifiable when you can answer these:
- Will I be adding programs P6 to P10 over the next X months?
- Do I want to abstract more of the functionality of the P* programs.  E.g.
are there hardcoded values or statements in the program that would want to
be changed in future invocations?
P1.sas
------------
%macro P1 (version = A /*default*/);
  %put version = &version;
....
%mend;
------------

*run P1 program;
%P1 (version=B);


-- 
Richard A. DeVenezia
http://www.devenezia.com/


0
rdevenezia1 (1435)
12/8/2005 12:32:21 PM
Reply: