DATA Step, Macro, Functions and more

Invoke SAS to run a macro automatically

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 126
Accepted Solution

Invoke SAS to run a macro automatically

Hi all,

I am just wondering if it is possible to invoke SAS without me having to initiate it in order to run a macro for a specific day.

In a nutshell if i want SAS, to run a proc means for example on a dataset at a specific day /time is it possible without me having to open SAS??

If yes, what do i need to do?

Kind regards and thnx in advance


Accepted Solutions
Solution
‎05-16-2012 11:52 AM
Frequent Contributor
Posts: 101

Re: Invoke SAS to run a macro automatically

Posted in reply to chemicalab

Here's a quick way. Let's say I have this simple program that runs a simple summary. I saved it in the same folder specified in the libname statement.

classmeans.sas

libname mylib 'c:\data\test';

proc summary data=sashelp.class nway;
class sex age;
var height weight;
output out=mylib.class_sum (drop=_Smiley Happy mean=;
run;

My OS is Windows XP. I created a batch file to execute the SAS program. Your path to the SAS executable may be different than mine. I saved the file in the same directory as the SAS program.

classmeans.cmd

"C:\Program Files\SAS\SASFoundation\9.2\sas.exe" -sysin c:\data\test\classmeans.sas

In the Control Panel, I ran the Scheduled Tasks task. When prompted for the program I wanted to schedule, I browsed to the c:\data\test folder where the classmeans.cmd file was located and selected it. I continued to follow the prompts to create the scheduled job. For this example, I scheduled it once to run 1 minute after creation of the job. I just wanted to make sure it worked. The summary file was created as scheduled.


View solution in original post


All Replies
Solution
‎05-16-2012 11:52 AM
Frequent Contributor
Posts: 101

Re: Invoke SAS to run a macro automatically

Posted in reply to chemicalab

Here's a quick way. Let's say I have this simple program that runs a simple summary. I saved it in the same folder specified in the libname statement.

classmeans.sas

libname mylib 'c:\data\test';

proc summary data=sashelp.class nway;
class sex age;
var height weight;
output out=mylib.class_sum (drop=_Smiley Happy mean=;
run;

My OS is Windows XP. I created a batch file to execute the SAS program. Your path to the SAS executable may be different than mine. I saved the file in the same directory as the SAS program.

classmeans.cmd

"C:\Program Files\SAS\SASFoundation\9.2\sas.exe" -sysin c:\data\test\classmeans.sas

In the Control Panel, I ran the Scheduled Tasks task. When prompted for the program I wanted to schedule, I browsed to the c:\data\test folder where the classmeans.cmd file was located and selected it. I continued to follow the prompts to create the scheduled job. For this example, I scheduled it once to run 1 minute after creation of the job. I just wanted to make sure it worked. The summary file was created as scheduled.


Super User
Super User
Posts: 7,076

Re: Invoke SAS to run a macro automatically

Posted in reply to chemicalab

It is not hard, you can do it the same way you would schedule any other job to run.

It will depend on your operating system.  If you are using Unix then you can use cron.  If it is windows then you will need to use a similar tool for Windows.

Basically on any system you can run SAS non-interactive by issuing the command: sas filename

Where sas is the command to run SAS on your system and filename is the name of the SAS program (most of which could be a macro call) that you want to run.  Once you have that working then schedule it to run when every you want.

Frequent Contributor
Posts: 126

Re: Invoke SAS to run a macro automatically

Posted in reply to chemicalab

Thnx guys for your insight i tried it and i got it to work

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 220 views
  • 3 likes
  • 3 in conversation