BookmarkSubscribeRSS Feed
hdg
Obsidian | Level 7 hdg
Obsidian | Level 7

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!

7 REPLIES 7
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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?

hdg
Obsidian | Level 7 hdg
Obsidian | Level 7

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

ballardw
Super User

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.

hdg
Obsidian | Level 7 hdg
Obsidian | Level 7

Thanks ballardw thats exactly what it was

jwillis
Quartz | Level 8

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"

hdg
Obsidian | Level 7 hdg
Obsidian | Level 7

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!

jwillis
Quartz | Level 8

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"

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 3738 views
  • 0 likes
  • 4 in conversation