<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Macro loop through dataset not comparing observation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-loop-through-dataset-not-comparing-observation/m-p/668199#M200255</link>
    <description>&lt;P&gt;Use an ARRAY to loop over variables in an observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macros are not needed, macros complicate the programming tremendously.&lt;/P&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
    <pubDate>Thu, 09 Jul 2020 22:04:28 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-07-09T22:04:28Z</dc:date>
    <item>
      <title>Macro loop through dataset not comparing observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-loop-through-dataset-not-comparing-observation/m-p/668191#M200247</link>
      <description>&lt;P&gt;Hi Community,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am quiet new to SAS Macro world and I am trying to achieve the following:&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks in advance for your precious help&lt;/P&gt;&lt;P&gt;Luca&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%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 (&amp;amp;iter.&amp;lt;= &amp;amp;datasetCount.);
/*get dates and if equal to today costcentre for dataset you will work on during this iteration*/
%put &amp;amp;datasetCount;
%put &amp;amp;iter;
%put &amp;amp;todaysdate;
data _NULL_;
set luca.ls (firstobs=&amp;amp;iter. obs=&amp;amp;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 &amp;amp;indate ***e**;
%put &amp;amp;indate2 ***d**;
%if %sysevalf("&amp;amp;indate."d = "&amp;amp;todaysdate."d) %then %do;
call symput("inLibref",Cost_Centre);
%put &amp;amp;inLibref ***b**; 
call symput("inMember",email);
%put &amp;amp;inMember;
%end;
run;





/*now you can apply your logic to the dataset*/
/*data &amp;amp;inLibref..&amp;amp;inMember.; *assuming you want to apply the changes to the dataset itself;
set work.trans2;
where cost_centre=&amp;amp;inLibref.;
/*** INSERT YOUR LOGIC HERE ***/
/*run;

/*** ANY OTHER PROCS/DATA STEPS ***/
/*just remember to use &amp;amp;inLibref..&amp;amp;inMember. to refer to the current dataset*/

/*increment the iterator of the loop*/
%let iter=%eval(&amp;amp;iter.+1);
%end;
%mend;

/*call the macro*/
%loopOverDatasets()&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Jul 2020 21:09:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-loop-through-dataset-not-comparing-observation/m-p/668191#M200247</guid>
      <dc:creator>lzanotti</dc:creator>
      <dc:date>2020-07-09T21:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: Macro loop through dataset not comparing observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-loop-through-dataset-not-comparing-observation/m-p/668199#M200255</link>
      <description>&lt;P&gt;Use an ARRAY to loop over variables in an observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macros are not needed, macros complicate the programming tremendously.&lt;/P&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Thu, 09 Jul 2020 22:04:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-loop-through-dataset-not-comparing-observation/m-p/668199#M200255</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-07-09T22:04:28Z</dc:date>
    </item>
  </channel>
</rss>

