I am running SAS in a Unix environment. I am attempting to do a grep of the errors in the directory containing all of my SAS logs, place the results in a macro variable, and include the results in the body of an email. The code works, but the output in the body of the email only includes the first 2 lines out of several (around 20 or more) produced by the grep command.
What can I change in order to have my email body include ALL of the lines produced by the grep command? Please reply with examples. Thanks.
data _null_; infile "cd /err/kept/here/;grep ERROR: *.log" pipe truncover; length x $300.; input x $300.; call symputx('errors',x); run; FILENAME Mailbox EMAIL SUBJECT="Email Containing Errors in SAS Code" content_type="TEXT/PLAIN"; data _null_; file Mailbox TO='<myemailadr@yahoo.com>'; put "Here are today's errors:"; put "&errors."; run;
Hi,
Maybe try like this:
FILENAME Mailbox EMAIL
SUBJECT="Email Containing Errors in SAS Code"
content_type="TEXT/PLAIN";
data _null_;
file Mailbox TO='<myemailadr@yahoo.com>';
if _N_=1 then put "Here are today's errors:";
infile "cd /err/kept/here/;grep ERROR: *.log" pipe truncover;
length x $300.;
input x $300.;
put x;
run;
All the best
Bart
Currently you are placing all of the output into a single macro variable.
I am going to guess that the result you see if from the "last" set of errors. With the single macro variable each log file read is going to overwrite the macro variable and the result is only from the last file.
I would create an actual data set instead of the DATA _NULL_ to collect the output. Then you have some data to examine.
And use that data set with PUT instead of macro variables.
Hi,
Maybe try like this:
FILENAME Mailbox EMAIL
SUBJECT="Email Containing Errors in SAS Code"
content_type="TEXT/PLAIN";
data _null_;
file Mailbox TO='<myemailadr@yahoo.com>';
if _N_=1 then put "Here are today's errors:";
infile "cd /err/kept/here/;grep ERROR: *.log" pipe truncover;
length x $300.;
input x $300.;
put x;
run;
All the best
Bart
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.