Hi
I have sas code which i run in unix sas by using sas followed by the code name or program name ex: sas test.sas
Now i was asked to create a trigger file to run the sas code on unix environment as it was running manually so far... script .sh .. i am not sure how to create the tirgger file could some help me on this.
The trigger file should have the current timestamp ...
Any help really appriciated!!
VK
What do you mean by trigger file? Are you trying to trigger the SAS program when a file exists? Or are you trying to write an output file when the SAS program runs?
I have sas code which i run on the unix sas.. that code contains stage tables which needed to feed the data into target tables.
After i run the code i need to collect the statistics i mean the row count of 5 to 6 stage tables and need to send a text file from the with the row count to other server.
The shell script should contain the sql statment with the select count(*) from table2 union all select count(*) from table2...... and it should generate txt file with current time stamp.
Some thing like this: test_current_timestamp.txt (text file)
Pls let me know if you have any queries!!!
Thanks
MVK
Hi,
Is this what you are looking for...
%global nobs;
%macro test(dset=);
%let dsid=%sysfunc(open(sashelp.&dset.));
%if &dsid %then
%do;
%let nobs=%sysfunc(attrn(&dsid,nobs));
%let rc=%sysfunc(close(&dsid));
%end;
data &dset;
count=&nobs;
table="&dset";
run;
proc append base=want data=&dset force;run;
%mend test;
%test(dset=adomsg);
%test(dset=adsmsg);
proc export data=want
outfile="F:\RD_output\want&sysdate..txt"
dbms=dlm;
delimiter=',';
run;
Thanks,
Shiva
Why not just modify the original program to write the txt file?
If not then create another program to write the txt file and call it after the first one.
#!/bin/ksh
sas oldprogram
sas newprogram
If you really want to avoid creating a second file with the SAS code then look at the -stdio command line option. This will allow you to embed the SAS code into your script.
Are you asking how to find out how many rows are in a table? Are they SAS datasets or database tables?
If they are SAS datasets then you can query DICTIONARY.TABLES. If they are in a database then you might need to use a query to determine the number of rows.
Writing TXT files with SAS is trivial.
data _null_;
set counts;
file 'test_current_timestamp.txt' ;
put memname nobs;
run;
You can use macro code or data step code and FILE statement options to generate a filename using date time. Or you could have the command script pass in the filename as run time parameter to the program.
Thanks Guys for helping me out ... I have invoked bteq script to create a text file .. this solutions provided by all gave me some idea.
1. Create a SAS program in a unix path - Eg. /opt/sas/Test.sas
2. Run the sas program using batch mode by create unix Script named as Test.sh
#! /bin/sh
/sas/config/Lev1/BatchServer/sasbatch.sh -log /opt/sas/TEST_#Y.#m.#d_#H.#M.#s.log -noprint -batch -noterminal -logparm "rollover=session" -sysin /opt/sas/Test.sas
rc=$?
exit $rc
3.Execute the script unix UNix console or use systask command in SAS editor
systask command "/opt/sas/Test.sh" shell wait;
4. Ensure the permissions are well defined the files created in Unix. Use chmod command
Cheers,
Ritesh
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.