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: Call for Content

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!

Submit your idea!

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.

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
  • 3 replies
  • 790 views
  • 1 like
  • 3 in conversation