DATA Step, Macro, Functions and more

Displaying Table contents in the Email

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 95
Accepted Solution

Displaying Table contents in the Email

Hi SAS Users,

 

Need some help with  displaying the Table contents into Email.

 

I have a variable called "FILENAME"  in a table 'FILES_TABLE"  where i stored all the filenames of 500 length. I have to put them in the email. & i used  "PUT" statement like below code.

 

%if &syserr=0 %then %do;
FILENAME outmail EMAIL
SUBJECT = "TEST FILES"
FROM = "xyz@xyz.com"
TO = "&to_email"
DATA _NULL_;
FILE outmail;
PUT "Hi All,";
PUT " ";
PUT "The following files have been created and dropped in the following path.";
PUT " ";
PUT "&filename";

PUT "Thanks,";
run;

I am seeing all the files, but they are coming in same line, or broken filenames in different lines, Dispaly is not clean. Due to one PUT staetement for all the files.

 

Any suggestions to make files look clean & orderly in the Email?

 

Thanks,

Ana

 

 

 

 

 


Accepted Solutions
Solution
‎01-27-2017 07:48 AM
Super User
Super User
Posts: 7,942

Re: Displaying Table contents in the Email

[ Edited ]

The reason all the filenames are coming out on one line is because you are outputting a string from macro varaible &filename.  You will need to loop of the macro list, if its comma separated then:

filename outmail email subject="test files" from="xyz@xyz.com" to="&to_email";
data _null_;
  file outmail;
  length fn $2000;
  put "hi all,";
  put " ";
  put "the following files have been created and dropped in the following path.";
  put " ";
  do i=1 to countw("&filename.",",");
    fn=scan("&filename.",i,",");
    put fn;
  end;
  put "thanks,";
run;

As always though, I would advise to avoid macro lists.  Put your data in datasets and process it from there, its what dataset are for.

Oh, and there really is no need to code all in upcase!

View solution in original post


All Replies
Solution
‎01-27-2017 07:48 AM
Super User
Super User
Posts: 7,942

Re: Displaying Table contents in the Email

[ Edited ]

The reason all the filenames are coming out on one line is because you are outputting a string from macro varaible &filename.  You will need to loop of the macro list, if its comma separated then:

filename outmail email subject="test files" from="xyz@xyz.com" to="&to_email";
data _null_;
  file outmail;
  length fn $2000;
  put "hi all,";
  put " ";
  put "the following files have been created and dropped in the following path.";
  put " ";
  do i=1 to countw("&filename.",",");
    fn=scan("&filename.",i,",");
    put fn;
  end;
  put "thanks,";
run;

As always though, I would advise to avoid macro lists.  Put your data in datasets and process it from there, its what dataset are for.

Oh, and there really is no need to code all in upcase!

Frequent Contributor
Posts: 95

Re: Displaying Table contents in the Email

Worked really well. Thanks for the suggestion.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 116 views
  • 0 likes
  • 2 in conversation