BookmarkSubscribeRSS Feed
lzanotti
Calcite | Level 5

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()
1 REPLY 1
PaigeMiller
Diamond | Level 26

Use an ARRAY to loop over variables in an observation.

 

Macros are not needed, macros complicate the programming tremendously.

 
--
Paige Miller

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 407 views
  • 0 likes
  • 2 in conversation