Wednesday, September 2, 2009

Scheduling your SAS program for Automated Execution and Read and Post Files in the Web Directly

For a production based sas scoring one needs a sas program to be run a file from a specific location (can be a FTP site) and output a file to the same location or different location or make it a web page for others to surf to.


Say, the pgm is daily number of visitors to a store or a hospital, as a time series, analyzed with all the bells and whistles of graphical output.


The pgm name is daily_update_4AM.sas.
The time to run is morning 4:00AM.
The input file is "ftp://www.CRMportals.com/outbound"
The output file has to be "ftp://www.CRMportals.com/todate/num_visitors.html"
The OS is WINDOWS.
Create a batch file (a file with .bat extension using a notepad editor)


start/w "C:\SAS 9.2\SAS.exe" –sysin C:\test\p1.sas -log C:\test\p1.log -log C:\Proj1\p1.log
start/w "C:\SAS 9.2\SAS.exe" –sysin C:\test\p2.sas -log C:\test\p2.log -log C:\Proj1\p2.log
start/w "C:\SAS 9.2\SAS.exe" –sysin C:\test\p2.sas -log C:\test\p2.log -log C:\Proj1\p2.log

After the program is written, use windows scheduling program to crontab your program.

start/w "C:\SAS 9.2\SAS.exe" –sysin "ftp:\\CRMportals.com\p1.sas" -log C:\test\p1.log -log "http:\\CRMportals.com\P1\p1.log"

The following section is from

READING FROM AN FTP SITE

Not only can FILENAME point to files on your current machine, but using the FTP options our programs can read and write data to any authorized FTP server. No extra products besides base SAS and FTP are required. Programs can be very flexible by reading the data from other computers, but keep in mind that there will be transfer time to move the
data from the other machine.

This example reads a file called sales in the directory /m/mydata/ from server public.client1.com:
filename myfile ftp 'sales' cd='/m/mydata'
user='guest' host='public.client1.com'
recfm=v prompt;
data mydata / view=mydata; /* Create a view */
infile myfile;
input x $10. y 4.;
run;i
proc print data=mydata; /* Print the data */
run;

READING FROM A URL
FILENAME can also point to a web page that contains data that we might be interested in. This effectively opens our program to millions of online files.

This example reads the first 15 records from a URL file and writes them to the SAS log with a PUT statement:
filename mydata url
'http://support.sas.com/techsup/service_intro.html';
data _null_;
infile mydata length=len;
input record $varying200. len;
put record $varying200. len;
if _n_=15 then stop;
run;




No comments: