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!
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?
WARNING: Apparent invocation of macro MyTools not resolved. %run_my_test is my main macro that does the analysis and produces reports
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.
Thanks ballardw thats exactly what it was
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"
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!
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"
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.
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.