BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ijm_wf
Fluorite | Level 6

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;
1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

3 REPLIES 3
ballardw
Super User

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.

 

 

ijm_wf
Fluorite | Level 6
Thanks for replying. Could you please provide an example illustrating what you are suggesting? For instance, should do I need to change both of the data _null_ 's to data sets or only the first one?
yabwon
Onyx | Level 15

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 822 views
  • 1 like
  • 3 in conversation