<?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: macros for date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macros-for-date/m-p/742371#M232201</link>
    <description>&lt;P&gt;This is bogus. You are still misusing the macro language, and you should&amp;nbsp;&lt;STRONG&gt;STUDY THE LOG!!!&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The macro creates this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data birth;
set birthdate;
where DOB="&amp;amp;date"d ;
z = cats("Happy birthday", name);
where DOB="&amp;amp;date"d ;
z = cats("Happy birthday", name);
where DOB="&amp;amp;date"d ;
z = cats("Happy birthday", name);
where DOB="&amp;amp;date"d ;
z = cats("Happy birthday", name);
where DOB="&amp;amp;date"d ;
z = cats("Happy birthday", name);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;just repeating the same statements for NO reason.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;OMIT&lt;/STRONG&gt; the macro loop entirely, it solves no purpose.&lt;/P&gt;</description>
    <pubDate>Wed, 19 May 2021 10:32:47 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-05-19T10:32:47Z</dc:date>
    <item>
      <title>macros for date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros-for-date/m-p/742356#M232187</link>
      <description>&lt;P&gt;I have below dataset&lt;/P&gt;
&lt;P&gt;data birthdate;&lt;BR /&gt;input name $ DoB date9. ;&lt;BR /&gt;format DoB date9.;&lt;BR /&gt;datalines;&lt;/P&gt;
&lt;P&gt;naomi 19-Nov-2004&lt;BR /&gt;pixxa 19-Nov-2006&lt;BR /&gt;katty 10-Nov-2009&lt;BR /&gt;Sneha 19-Nov-2006&lt;BR /&gt;Aron&amp;nbsp; 30-Oct-2009&lt;BR /&gt;Snaya 19-Feb-2006&lt;BR /&gt;Army 19-May-2009&lt;BR /&gt;Page 20-Feb-1982&lt;BR /&gt;Suze 11-Sep-1993&lt;BR /&gt;Taity 30-Oct-2009&lt;BR /&gt;Sainaa 19-Feb-2006&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create a macro where&amp;nbsp; for a given date value , it will check for first 5 records and if it matches it sends "happy birthday &amp;lt;person name&amp;gt; ".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it means if DOB =19-Nov-2006 then it will send happy bithday to both pixxa and sneha.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 May 2021 09:11:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros-for-date/m-p/742356#M232187</guid>
      <dc:creator>Aexor</dc:creator>
      <dc:date>2021-05-19T09:11:18Z</dc:date>
    </item>
    <item>
      <title>Re: macros for date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros-for-date/m-p/742358#M232189</link>
      <description>&lt;P&gt;What do yo mean by "send"?&lt;/P&gt;
&lt;P&gt;This outputs the messages:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data birthdate;
input name $ DoB :date11.;
format DoB date9.;
datalines;
naomi 19-Nov-2004
pixxa 19-Nov-2006
katty 10-Nov-2009
Sneha 19-Nov-2006
Aron  30-Oct-2009
Snaya 19-Feb-2006
Army 19-May-2009
Page 20-Feb-1982
Suze 11-Sep-1993
Taity 30-Oct-2009
Sainaa 19-Feb-2006
;

proc sql;
  select "Happy birthday " !! name
  from birthdate (obs=5)
  group by dob
  having count(*) &amp;gt; 1
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that your informat as posted is too short, the DOB strings are 11 characters long; therefore, with your code, all years would be either 2019 or 2020.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/327170"&gt;@Aexor&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have below dataset&lt;/P&gt;
&lt;P&gt;data birthdate;&lt;BR /&gt;input name $ DoB date9. ;&lt;BR /&gt;format DoB date9.;&lt;BR /&gt;datalines;&lt;/P&gt;
&lt;P&gt;naomi 19-Nov-2004&lt;BR /&gt;pixxa 19-Nov-2006&lt;BR /&gt;katty 10-Nov-2009&lt;BR /&gt;Sneha 19-Nov-2006&lt;BR /&gt;Aron&amp;nbsp; 30-Oct-2009&lt;BR /&gt;Snaya 19-Feb-2006&lt;BR /&gt;Army 19-May-2009&lt;BR /&gt;Page 20-Feb-1982&lt;BR /&gt;Suze 11-Sep-1993&lt;BR /&gt;Taity 30-Oct-2009&lt;BR /&gt;Sainaa 19-Feb-2006&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create a macro where&amp;nbsp; for a given date value , it will check for first 5 records and if it matches it sends "happy birthday &amp;lt;person name&amp;gt; ".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it means if DOB =19-Nov-2006 then it will send happy bithday to both pixxa and sneha.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 May 2021 09:20:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros-for-date/m-p/742358#M232189</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-05-19T09:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: macros for date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros-for-date/m-p/742359#M232190</link>
      <description>Thank you so much! Can we do same thing in data step ?&lt;BR /&gt;Could you please check what went wrong here :&lt;BR /&gt;&lt;BR /&gt;%macro birthmsg(date,i,n);&lt;BR /&gt;data birth;&lt;BR /&gt;set birthdate;&lt;BR /&gt;%do i =&amp;amp;i %to &amp;amp;n;&lt;BR /&gt;where DOB="&amp;amp;date"d ;&lt;BR /&gt;%put "Happy birthday" || name;&lt;BR /&gt;%end;&lt;BR /&gt;%mend birthmsg;&lt;BR /&gt;&lt;BR /&gt;options symbolgen mprint;&lt;BR /&gt;%birthmsg(19-Nov-2004,1,2)&lt;BR /&gt;&lt;BR /&gt;I am having doubt in how can we check for dates in macro variable?&lt;BR /&gt;Please help</description>
      <pubDate>Wed, 19 May 2021 09:24:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros-for-date/m-p/742359#M232190</guid>
      <dc:creator>Aexor</dc:creator>
      <dc:date>2021-05-19T09:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: macros for date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros-for-date/m-p/742367#M232197</link>
      <description>&lt;P&gt;That's because you abuse macro language for something it can't do. Macro statements do not have access to data step variables, as the macro statements are resolved before the data step is even compiled.&lt;/P&gt;
&lt;P&gt;The macro&amp;nbsp;&lt;STRONG&gt;PRE&lt;/STRONG&gt;processor is a code generator that helps you in writing dynamic or repeating code, it does&amp;nbsp;&lt;STRONG&gt;NOT&lt;/STRONG&gt; work with data.&lt;/P&gt;
&lt;P&gt;Your macro creates this code (&lt;U&gt;exactly&lt;/U&gt; this code):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data birth;
set birthdate;
where DOB="19-Nov-2004"d ;
where DOB="19-Nov-2004"d ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and, while doing that, puts these messages to the log:&lt;/P&gt;
&lt;PRE&gt;"Happy birthday" || name
"Happy birthday" || name&lt;/PRE&gt;
&lt;P&gt;Then the data step runs, because SAS Studio or Enterprise Guide helps you out by providing a RUN statement, and creates a dataset according to the WHERE condition (only the second, as it replaces the first; a NOTE about that is also found in the log)&lt;/P&gt;
&lt;P&gt;You need to use data step code, and if I read your intentions right, you want the occurrences between &amp;amp;i and &amp;amp;n to appear in the output dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro birthmsg(date,i,n);

data birth;
set birthdate;
where DOB="&amp;amp;date."d;
counter + 1;
if &amp;amp;i. le counter le &amp;amp;n.;
message = "Happy birthday" || name;
run;

%mend birthmsg;

%birthmsg(19-Nov-2006,1,2)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I changed the year to 2006, as there's only one date in 2004&lt;/P&gt;</description>
      <pubDate>Wed, 19 May 2021 10:03:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros-for-date/m-p/742367#M232197</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-05-19T10:03:59Z</dc:date>
    </item>
    <item>
      <title>Re: macros for date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros-for-date/m-p/742370#M232200</link>
      <description>Thanks for clarifying my doubts.&lt;BR /&gt;Though i updated the code to this and it worked too&lt;BR /&gt;&lt;BR /&gt;%macro birthmsg(date,i,n);&lt;BR /&gt;data birth;&lt;BR /&gt;set birthdate;&lt;BR /&gt;%do i =&amp;amp;i %to &amp;amp;n;&lt;BR /&gt;where DOB="&amp;amp;date"d ;&lt;BR /&gt;z = cats("Happy birthday", name);&lt;BR /&gt;%end;&lt;BR /&gt;%mend birthmsg;&lt;BR /&gt;&lt;BR /&gt;options symbolgen mprint;&lt;BR /&gt;%birthmsg(19-Nov-2006,1,5)&lt;BR /&gt;</description>
      <pubDate>Wed, 19 May 2021 10:25:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros-for-date/m-p/742370#M232200</guid>
      <dc:creator>Aexor</dc:creator>
      <dc:date>2021-05-19T10:25:20Z</dc:date>
    </item>
    <item>
      <title>Re: macros for date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros-for-date/m-p/742371#M232201</link>
      <description>&lt;P&gt;This is bogus. You are still misusing the macro language, and you should&amp;nbsp;&lt;STRONG&gt;STUDY THE LOG!!!&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The macro creates this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data birth;
set birthdate;
where DOB="&amp;amp;date"d ;
z = cats("Happy birthday", name);
where DOB="&amp;amp;date"d ;
z = cats("Happy birthday", name);
where DOB="&amp;amp;date"d ;
z = cats("Happy birthday", name);
where DOB="&amp;amp;date"d ;
z = cats("Happy birthday", name);
where DOB="&amp;amp;date"d ;
z = cats("Happy birthday", name);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;just repeating the same statements for NO reason.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;OMIT&lt;/STRONG&gt; the macro loop entirely, it solves no purpose.&lt;/P&gt;</description>
      <pubDate>Wed, 19 May 2021 10:32:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros-for-date/m-p/742371#M232201</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-05-19T10:32:47Z</dc:date>
    </item>
  </channel>
</rss>

