I have two SAS codes 1 and 2, I want to merge the two codes to send an automatic email from SAS, I want to replace the put of the second code (PUT "Code1???????????????? ") by that of the first, I do not know how to do that, can you help me?
/**********Code1********/
%macro Controle_QDD (Branche);
data SITMVT&Branche.;
set Stock&Branche.;
merge Stock&Branche. (in=A) Base&Branche. (in=B);
by &Varlist.
;
if A and not B;
run;
proc sql noprint;
select count(*) as NB&Branche.
from SITMVT&Branche.;
quit;
%if NB&Branche. > 0 %then
%put Le contrôle QDD est OK pour SITMVT&Branche. ;
%else
%put Le contrôle est KO pour SITMVT&Branche. Je vous invite à vérifier les résultats en exécutant le code ;
%mend;
%Controle_QDD(B);
%Controle_QDD(L);
/******Code2********/
filename mymail email FROM= "XXX"
TO=(
"XXX"
)
Cc=("XXX"
)
TYPE="text/html"
CONTENT_TYPE="text/html";
DATA _null_;
FILE mymail
SUBJECT="Controle QDD ";
PUT 'Bonjour,';
PUT '<br>';
PUT '<br>';
PUT '<br>';
PUT "Code1???????????????? "; /**** replace by Code 1 ????****/
PUT '<br>';
PUT 'Pour avis :-)';
PUT '<br>';
PUT '<br>';
PUT '<i>Note: ce mail est généré automatiquement, merci de ne pas y répondre.</i> ';
PUT '<br>';
PUT '<Cordialement,>';
RUN;
```---------------------------------
Your 'Code 1' won't work as it is. It looks like you're trying to create a macro variable called NB&Branche in the SQL step, but your existing code is only creating a temporary SQL variable. You need:
to store the value in to a macro variable. Then your following macro IF statements need to resolve the value of that macro variable like this (note the extra && at the beginning):
And you can basically just repeat that part in your 'Code 2':
to conditionally add one message or the other to your email. The whole thing could be made a lot neater - you could save the required message for each 'branche' to a macro variable during 'Code 1', for example - but that should be enough to get it working...
Bon chance!