Help using Base SAS procedures

.sh script to run the sas code in unix sas

Reply
Occasional Contributor
Posts: 12

.sh script to run the sas code in unix sas

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

Super User
Super User
Posts: 6,502

Re: .sh script to run the sas code in unix sas

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?

Occasional Contributor
Posts: 12

Re: .sh script to run the sas code in unix sas

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

Super Contributor
Posts: 349

Re: .sh script to run the sas code in unix sas

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

Super User
Super User
Posts: 6,502

Re: .sh script to run the sas code in unix sas

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.

Occasional Contributor
Posts: 12

Re: .sh script to run the sas code in unix sas

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.

Ask a Question
Discussion stats
  • 5 replies
  • 2213 views
  • 6 likes
  • 3 in conversation