BookmarkSubscribeRSS Feed
Calcite | Level 5

Hello everyone, 


I have a program that runs on the 5th of each month. The program is used to import an excel file located in a directory that I share with another person. This file is added to the directory by the another person.

At the end of the program, an email is sent to me to verify that the file, if it exists, has been imported.

If the file doesn't exist, the program runs again the next 10 days.


What I want to do, if the file has not been added 5 days after the first execution (so the 10th of each month), is to send an email to this second person to remind him to add the file to the directory.


So I tried something like this :


%Macro Send_email(nb=);

%let _date= %sysfunc(today(),DDMMYY10.);
%put &_date.;
%let my = %sysfunc(today(),MMYYS.); %put &my.; %if %sysfunc(fileexist(&test_file_1.)) %then %do; /*Email to me if the file is added*/ %end; %else %if &_date="10/&my." %then %do ; /*Email to the other person if the file is not added*/



But I think the problem with this code is that the program will still send the email on the 10th even if the file exist.

I don't know how to make SAS understand that sending email to the other person is only when the file is still not added on the 10th of the month.


Thank you in advance for your help !


Best regards,

Lapis Lazuli | Level 10

Just add an additional check if the file exists or not to the second if statement


%let rc=%sysfunc(fileexist(/sas/temp/bbs_m.log));
%if &rc=0 and &_date="10/&my." %then %put Hello;
Calcite | Level 5



I have another problem.


The variable "rc" seems to work but I have a problem with the other variable "_date".

Let's say that I didn't receive the file today (so the 9th) and that I want to send an email tomorrow, with the actual code, I got an error.


%let rc=%sysfunc(fileexist(&file_test_1.));

%let my = %sysfunc(today(),MMYYS.); %put &my.; /*01/2020*/ %let _date= %sysfunc(today(),DDMMYY10.); %put ===> &_date.; /*09/01/2020*/

%if &rc=1 %then %do;
/*First mail if it worked*/

%else %if &rc=0 and &_date="10/&my." %then %do;
/*Second mail if it didn't work*/

So I get the following messages :

The condition %IF &rc=1 is FALSE
The condition %IF &rc=0 and &_date="10/&my." is FALSE

Which is normal, but if I change the "10/&my." for "09/&my.", I will get the same message and all the conditions will be false.


My question is, how can I change the variable _date so that if I put today's date, the condition is true ?


Thank you in advance for your help !


Best regards,


Lapis Lazuli | Level 10

Hey @Mick_lb ,


I'm starting out with a few pointers to help you along the way and will have a final answer at the end.


What you are running into here is a classic macro if-condition problem.

The get a better understanding of what is happening inside of the macro you should use the following options:

options symbolgen mlogic mprint;

You can deactivete them again with a e.g options nosymbolgen;


Now you can get a better look at how your variables are assigned and evaluted during the macro execution.


Next step lets assign the value of your if condition to a variable and show it in the log:

%let x = "10/&my.";
%put x=&x;

This result in x="10/01/2020" and if you take a look at the variable &_date it shows 10/01/2020 now you see a clear difference. The two enclosing ". Well they just signify you might say but it is important to note that the macro language is just generating text in and of itself and thus " is another character and now it should be clear that the if-condition can actually never be true because of the way macros in SAS work.


Now what is the solution? Just dropping the " in the if condition works perfectly.


And now a full working example - which I hope works as you intent:

options symbolgen mlogic mprint;

%macro test;
	%let rc=0;
	%let my = %sysfunc(today(),MMYYS.);
	%put &my.; /*01/2020*/
	%let _date= %sysfunc(today(),DDMMYY10.);
	%let x = 10/&my.;
	%put =&x;
	%put ===> &_date.; /*09/01/2020*/

	%if &rc=1 %then
			%put GOODBYE;
	%else %if &rc=0 and &_date=10/&my. %then
			%put HELLO;



Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.


Register now!

5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1 like
  • 2 in conversation