Help using Base SAS procedures

running batch file from windows

Reply
Frequent Contributor
Frequent Contributor
Posts: 79

running batch file from windows

Dear all,

I am struggling with this a bit. I have SAS 9.2 and need to the following

1) Run some SAS code - lets say hello.sas

2) Run matlab .m file

3) Run SAS code again


I would like to put these steps in a *.BAT file


My hello.sas calls additional macros looks like the following


%macro initialize;

%let path = C:\temp;

include "&path\MyTools.sas";

%MyTools(&path);

%mend;


%initialize;

%run_my_test;


The MyTools macro incldues all macros used by the program.



not sure how i can do this at least to get the first simple test rolling

"C:\Program Files\SAS\...\sas.exe" -sysin "C:\temp\hello.sas" all it does it opens sas and not do anything else Thanks for your help!

Super User
Super User
Posts: 7,401

Re: running batch file from windows

What does it say in your log?  All I can see that your SAS program does is to include some other code, then call %run_my_test; whatever that does?

Frequent Contributor
Frequent Contributor
Posts: 79

Re: running batch file from windows

WARNING: Apparent invocation of macro MyTools not         resolved. %run_my_test is my main macro that does the analysis and produces reports

Super User
Posts: 10,500

Re: running batch file from windows

Partially you may need %include. Without the % you should get an error.

And a warning that your macros weren't found as the code in the %include file never executed.

Frequent Contributor
Frequent Contributor
Posts: 79

Re: running batch file from windows

Thanks ballardw thats exactly what it was

Regular Contributor
Posts: 217

Re: running batch file from windows

Dear HDG,

When running a batch SAS job from my Windows PC, I learned that you have to 1. open a batch executed SAS session; 2. Bring in the code that has any macros and execute the macros so that they are defined (compiled) in the batch session; and 3 run the actual code.  Sometimes I had a batch job that opened a SAS session (.exe); that called a SAS program (.sas) that defined the libraries (filename and libname statements) and 'included' the macro code (.sas) and finally 'included' the processing code.  In every situation, I had to define my libraries and macros before I could execute any other code.  I am looking for code examples and will send them when I find them.  

Message was edited by: James Willis HDG, I used a .cmd file to start a SAS session that executed my REFRESH tables SAS routine.  Inside the tables.sas file were library statements and include statements.  The library definitions and macro definitions were always included before I included the code that actually executed the refresh code. @echo on rem                      'be certain of where the batch file is looking. START/W C:\"Program Files"\SAS\"SAS 9.1"\sas.exe -sysin "....path....\REFRESH SIM-Cmed tables.sas"

Frequent Contributor
Frequent Contributor
Posts: 79

Re: running batch file from windows

Thanks that very helpful jwillis!

I have got it to work it was really dumb mistake of not having the macro definitions being included correctly.

I do have another question if say my macro

test.sas looks like this

%macro Initialize;

%mend;

%macro getdata;

%Initialize;

%mend;

%macro domything;

%Initialize;

%mend;

How  do i invoke these macros separately in my bat file

"C:\Program Files\SAS\SASFoundation\9.2(32-bit)\sas.exe" -sysin   "First invoke getdata"

"C:\Program Files\SAS\SASFoundation\9.2(32-bit)\sas.exe" -sysin  "Then do mything"

Thanks for your help!

Regular Contributor
Posts: 217

Re: running batch file from windows

HDG,

I last ran .cmd files in 2004 so I am rusty.  There are several different ways to do what you need. I'll work on this tonight and tomorrow and see if I can find what I want to show you.  You cannot actually "call" a macro from a .cmd or .bat file.  Every time you  start a SAS session, you wipe out any macros previously defined in a session **.  When you invoke "getdata", you are not executing a macro, you are executing a SAS program (*.sas).  You have to initialize your libraries and macros (include a sas file with all the initializations) every time you execute sas.exe.

** unless you compile them to a permanent library.  I do not have the skillset of using permanent compiled macros.

stored in initialize.sas.

%macro Initialize;

%mend;

%initialize;

stored in getdata.sas.

%macro getdata;

%mend;

%getdata;

stored in domything.sas.

%macro domything;

%mend;

%getdata;

stored in callgetdata.sas;

%include Initialize.sas;

%include getdata.sas;

stored in calldomything.sas;

%include Initialize.sas;

%include calldomything.sas;

How  do i invoke these macros separately in my bat file

"C:\Program Files\SAS\SASFoundation\9.2(32-bit)\sas.exe" -sysin   "First invoke getdata"

"C:\Program Files\SAS\SASFoundation\9.2(32-bit)\sas.exe" -sysin  "Then do mything"

Ask a Question
Discussion stats
  • 7 replies
  • 1505 views
  • 0 likes
  • 4 in conversation