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

Hello,

 

I have table containing email address , name and names of files. I have to sand an email to each person and writing down the list of files' names.

 

fileexample.png

I created a macro %putt that can do what I'm looking for.

 

filename MYEMAIL email;
 data _null_;
 set password_name_path;
  file MYEMAIL;
	%MACRO PUTT(NBR);
	%DO I = 1 %TO &NBR;
	 PUT  file&I ; 
	 put ;
	%END;
	%MEND PUTT;
 put '!EM_TO!' mail;
 put '!EM_FROM!' "XXX@gmail.com";
 /*put '!EM_CC!' " ";*/
 put '!EM_SUBJECT! File’sname  ' ;
 put "Hello "name "," ; 
 put ;
 put "======================================================================================================";

 put ;
 put "the names files are :" ;
 put ;
 %PUTT(&maxfile);
 put ;
 
 put "======================================================================================================";
 put '!EM_SEND!';
 put '!EM_NEWMSG!';
 put '!EM_ABORT!';
run;

&maxfile is a macro variable which has the max value of numbers of file. 4 in the example above.

The program works properly but I have 4 lines for each email sent by SAS.

mail.png 

can anyone help me how to put avoid printing black lines when we have only some files (file1, file2 for exp).

Thank you 

1 ACCEPTED SOLUTION

Accepted Solutions
Nihal
Fluorite | Level 6

Hi @DaveHorne 

 

Thank you very much for this easy solution.

Its works

Nihal

View solution in original post

7 REPLIES 7
Cynthia_sas
SAS Super FREQ
Hi:
Every PUT; statement in your code is writing a blank line. So inside your DO loop, you have a put; that will be written each time through the loop. Then you have extra put; statements after the Hello and before and after the lines.

The first thing I'd recommend is remove a few of the
put;
statements that you have and see whether that improves your spacing.
Cynthia
Nihal
Fluorite | Level 6

Thank you for your answer.

 

You're right. But what I'm asking for is how to write a code to tell sas to put file1 and stops instead of putting 3 blank lines.

Note : the value of macro variable "&maxfile" =4

May be adding a do loop?

 

Thanks,

 

 

 

 

Reeza
Super User
Why you have a macro embedde in a data step. That likely is not a good idea. It makes things confusing is one reason, the other is it makes it difficult to debug. Why are you looking 4 times if you have only one file? Either modify the loop or add an %IF/%THEN afterwards to check if the macro variable has a value before displaying it. You can finding some examples in the Macro Appendix in the documentation.
DaveHorne
SAS Employee

Hi @Nihal, here's an alternative just listing the filenames on one row.  When I have short emails like this I also put the same information in the subject line so that I don't even have to open the email.  In the put statements, the / tells SAS to go to a new line (making a blank line).

 

filename MYEMAIL email;
 data _null_;
 set password_name_path;
 maxfile = CATX(' ', file1, file2, file3, file4);
 file MYEMAIL;
 put '!EM_TO!' mail;
 put '!EM_FROM!' "XXX@gmail.com";
 put '!EM_SUBJECT!' 'the names files are: ' maxfile ;
 put "Hello " name "," ;
 put / "======================================================================================================";
 put / "the names files are: " maxfile ;
 put / "======================================================================================================";
 put '!EM_SEND!';
 put '!EM_NEWMSG!';
 put '!EM_ABORT!';
run;

Hope this helps.

DaveHorne
SAS Employee

Hi @Nihal, here's another version with the files listed on separate lines (and I used the shortcut notation for the dashed lines):

 

filename MYEMAIL email;
 data _null_;
 set password_name_path;
 maxfile = CATX(' ', file1, file2, file3, file4);
 file MYEMAIL;
 put '!EM_TO!' mail;
 put '!EM_FROM!' "XXX@gmail.com";
 put '!EM_SUBJECT!' 'the names files are: ' maxfile ;
 put "Hello " name "," ;
 put / 30*"=";
 put / "The names files are:";
 if file1 > '' then put / file1;   
 if file2 > '' then put / file2;   
 if file3 > '' then put / file3;   
 if file4 > '' then put / file4;   
 put / 30*"=";
 put '!EM_SEND!';
 put '!EM_NEWMSG!';
 put '!EM_ABORT!';
run;
Nihal
Fluorite | Level 6

Hi @DaveHorne 

 

Thank you very much for this easy solution.

Its works

Nihal

Reeza
Super User
You should mark Dave’s solution as the answer, not your response.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 7 replies
  • 3429 views
  • 0 likes
  • 4 in conversation