DATA Step, Macro, Functions and more

automating the execution?

Reply
SAS Employee
Posts: 73

automating the execution?

Q: If you want to execute a piece of SAS code only on the first Friday of every month, how will you achieve it? Write a sample code (in SAS) for the same.
Super User
Posts: 5,257

Re: automating the execution?

A: I suppose most schedulers has this functionality. But if you want to implement it using SAS, I suggest that you take a look at macro programming, together with the DAY and WEEKDAY functions.

/Linus
Data never sleeps
SAS Super FREQ
Posts: 8,743

Re: automating the execution?

Hi:
Look at step #9 in this paper:
http://www2.sas.com/proceedings/sugi28/056-28.pdf

This shows a particular report being submitted when the month is 6, 7 or 8 using a SAS Macro program. Your code would need to find and define a different date interval (probably using SAS functions)....but the overall approach would be similar.

I do suggest that you make sure you understand the code in steps 1-8 before jumping into step 9.

cynthia
Super Contributor
Super Contributor
Posts: 3,174

Re: automating the execution?

Depending on your OS, there is likely an option for scheduling a "task" which would be to launch SAS and pass it your SYSIN which would contain the SAS program you want to execute.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic/post:

sas batch sysin site:sas.com
Contributor
Posts: 36

Re: automating the execution?

Question is if you want to execute a complete program on Friday or just a section of code in a program only on Friday.
For the first you need a scheduler in your operating system.
For the second I would suggest some macro code.

data date_parms;
dow=put(today(),weekday1.);
call symputx('dow',dow);
run;

Macro variable dow is the day of week. Friday is day 6. Within the macro program you would use the following code.

%if &dow=6 %then
%do;
code segment;
%end;
Frequent Contributor
Posts: 91

Re: automating the execution?

Barheat - thanks for the day of week tip - I have been trying to use something like this but must have missed something along the way.



Pavan@SAS- We are running 9.2 on a remote server with XP, and this is how I get to the scheduler:

Start -> All Programs -> Accessories -> System Tools -> Scheduled Tasks

And in the run window I have the following all in one string:

D:\SAS9.2\SASFoundation\9.2\sas.exe
-AUTOEXEC D:\SASData\myarea\AUTOEXEC.SAS
-SYSIN D:\SASData\myarea\run_this_file.sas

Good luck!

Wendy T Message was edited by: WendyT
Ask a Question
Discussion stats
  • 5 replies
  • 258 views
  • 0 likes
  • 6 in conversation