Hi Community, I am quiet new to SAS Macro world and I am trying to achieve the following: Given a controller dataset (image attached luca.ds) I would like to loop through the observation and check if m1date is today (potentially also m2date). If the condition is met, I would like to store the cost_centre and email, and use it to create partitions based on cost_centre from a master dataset with that names and send automated emails containing those. I am writing the following code but as per log attached it seems is not getting any record and I do not know where I am wrong. If I increase the number of datasetCount it fetch the last record but not the first. thanks in advance for your precious help Luca %macro loopOverDatasets();
%local datasetCount iter inLibref inMember;
%let todaysdate=%sysfunc(today(),date9);
/*get number of records*/
proc sql noprint;
select count(*)
into :datasetCount
from luca.ls;
quit;
/*initiate loop*/
%let iter=1;
%do %while (&iter.<= &datasetCount.);
/*get dates and if equal to today costcentre for dataset you will work on during this iteration*/
%put &datasetCount;
%put &iter;
%put &todaysdate;
data _NULL_;
set luca.ls (firstobs=&iter. obs=&iter.); *only read 1 record;
*write the dates to the macro variables;
call symput("indate",put(m1date,date9.));
call symput("indate2",put(m2date,date9.));
%put &indate ***e**;
%put &indate2 ***d**;
%if %sysevalf("&indate."d = "&todaysdate."d) %then %do;
call symput("inLibref",Cost_Centre);
%put &inLibref ***b**;
call symput("inMember",email);
%put &inMember;
%end;
run;
/*now you can apply your logic to the dataset*/
/*data &inLibref..&inMember.; *assuming you want to apply the changes to the dataset itself;
set work.trans2;
where cost_centre=&inLibref.;
/*** INSERT YOUR LOGIC HERE ***/
/*run;
/*** ANY OTHER PROCS/DATA STEPS ***/
/*just remember to use &inLibref..&inMember. to refer to the current dataset*/
/*increment the iterator of the loop*/
%let iter=%eval(&iter.+1);
%end;
%mend;
/*call the macro*/
%loopOverDatasets()
... View more