<?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 Proc SQL equivalent for a data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-equivalent-for-a-data-step/m-p/815320#M321815</link>
    <description>&lt;PRE&gt;%let num=%sysfunc(intck(month,'01jan2022'd,%sysfunc(today())));

data b;
set a;
%macro bb;
%do n=0 %to &amp;amp;num;
%let beg=%sysfunc(putn(%sysfunc(intnx(month,%sysfunc(today()),-&amp;amp;n)),date9.));
%let end=%sysfunc(putn(%sysfunc(intnx(month,%sysfunc(today()),-&amp;amp;n,end)),date9.));
%let mon=%sysfunc(putn(%sysfunc(intnx(month,%sysfunc(today()),-&amp;amp;n)),yymmd.));

 if begin_date le "&amp;amp;end"d and end_date ge "&amp;amp;beg"d 
        then do;
            mon="&amp;amp;mon"; 
	output;
	end; 
%end;
%mend;
%bb
run;&lt;/PRE&gt;&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know the Proc SQL equivalent for the attached SAS Data Step? After running the attached the SAS Data Step code, data b would have multiple records correspond to one record in data a (when meets the condition, output a new record).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Thu, 26 May 2022 22:47:17 GMT</pubDate>
    <dc:creator>wbsjd</dc:creator>
    <dc:date>2022-05-26T22:47:17Z</dc:date>
    <item>
      <title>Proc SQL equivalent for a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-equivalent-for-a-data-step/m-p/815320#M321815</link>
      <description>&lt;PRE&gt;%let num=%sysfunc(intck(month,'01jan2022'd,%sysfunc(today())));

data b;
set a;
%macro bb;
%do n=0 %to &amp;amp;num;
%let beg=%sysfunc(putn(%sysfunc(intnx(month,%sysfunc(today()),-&amp;amp;n)),date9.));
%let end=%sysfunc(putn(%sysfunc(intnx(month,%sysfunc(today()),-&amp;amp;n,end)),date9.));
%let mon=%sysfunc(putn(%sysfunc(intnx(month,%sysfunc(today()),-&amp;amp;n)),yymmd.));

 if begin_date le "&amp;amp;end"d and end_date ge "&amp;amp;beg"d 
        then do;
            mon="&amp;amp;mon"; 
	output;
	end; 
%end;
%mend;
%bb
run;&lt;/PRE&gt;&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know the Proc SQL equivalent for the attached SAS Data Step? After running the attached the SAS Data Step code, data b would have multiple records correspond to one record in data a (when meets the condition, output a new record).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2022 22:47:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-equivalent-for-a-data-step/m-p/815320#M321815</guid>
      <dc:creator>wbsjd</dc:creator>
      <dc:date>2022-05-26T22:47:17Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL equivalent for a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-equivalent-for-a-data-step/m-p/815321#M321816</link>
      <description>&lt;P&gt;Yikes.&amp;nbsp; That is a very confusing way to write a data step.&amp;nbsp; Remember the macro processor (the macro &lt;STRONG&gt;pre&lt;/STRONG&gt;-processor) finishes its work before the resulting text is passed onto SAS itself to interpret. So putting macro code, ,especially macro &lt;STRONG&gt;definitions,&lt;/STRONG&gt;&amp;nbsp;in the middle of a data step is just going to confuse the humans trying to read the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So let's first try to untangle that so we can see what type of data step you are trying to generate with that macro code.&amp;nbsp; So I think you are trying to run something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro bb(num);
%local n beg end mon;
%do n=0 %to &amp;amp;num;
  %let beg=%sysfunc(putn(%sysfunc(intnx(month,%sysfunc(today()),-&amp;amp;n)),date9.));
  %let end=%sysfunc(putn(%sysfunc(intnx(month,%sysfunc(today()),-&amp;amp;n,end)),date9.));
  %let mon=%sysfunc(putn(%sysfunc(intnx(month,%sysfunc(today()),-&amp;amp;n)),yymmd.));

if begin_date le "&amp;amp;end"d and end_date ge "&amp;amp;beg"d then do;
   mon="&amp;amp;mon"; 
   output;
end; 

%end;
%mend;

data b;
  set a;
  %bb(num=%sysfunc(intck(month,'01jan2022'd,%sysfunc(today()))))
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which would be a lot easier without the macro code. Perhaps like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b;
  set a;
  do offset=0 to intck('month',max(begin_date,'01JAN2022'd),min(end_date,today));
    mon = put(intnx('month',max(begin_date,'01JAN2022'd),offset),mmddd7.);
    output;
  end;
  drop offset;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you wanted to so something like that in SQL code then create the target months as a dataset and join the target months with the data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data months;
  do offset=0 to intck('month','01JAN2022'd,today());
     begdt = intnx('month','01JAN2022'd,offset);
     enddt = intnx('month','01JAN2022'd,offset,'end');
     mon = put(begdt,yymmd7.);
    output;
  end;
run;
proc sql;
create table b as
  select a.*,b.mon
  from a inner join months b
  on a.begin_date le b.enddt and a.end_date ge b.begdt
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2022 23:14:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-equivalent-for-a-data-step/m-p/815321#M321816</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-26T23:14:41Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL equivalent for a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-equivalent-for-a-data-step/m-p/815323#M321818</link>
      <description>&lt;P&gt;Your solution is awesome, works perfectly, thank you so much!&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2022 00:06:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-equivalent-for-a-data-step/m-p/815323#M321818</guid>
      <dc:creator>wbsjd</dc:creator>
      <dc:date>2022-05-27T00:06:48Z</dc:date>
    </item>
  </channel>
</rss>

