BookmarkSubscribeRSS Feed
mvk_sas
Calcite | Level 5

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

6 REPLIES 6
Tom
Super User Tom
Super User

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?

mvk_sas
Calcite | Level 5

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

shivas
Pyrite | Level 9

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

Tom
Super User Tom
Super User

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.

mvk_sas
Calcite | Level 5

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.

riteshfrank
Fluorite | Level 6

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

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 6292 views
  • 6 likes
  • 4 in conversation