<?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 Dynamic last dat of the month using year and month in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-last-dat-of-the-month-using-year-and-month/m-p/740972#M231561</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am having difficulty in creating a dynamic last day of the month date9. format by using yyyymm format.&lt;/P&gt;
&lt;P&gt;I have created below code, and&amp;nbsp;at present &amp;nbsp;i am manually changing end_date value (e.g., -51, -52, so on). I want to eliminate this and macro should pick the last day of the month&amp;nbsp;from %check(201701 201702)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;end_date values in &lt;STRONG&gt;dec_data&lt;/STRONG&gt; dataset will in 03JAN2017, 10JAN2017, 31JAN2017 so on&amp;nbsp;format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;

%macro check(months);

%let months_count = %sysfunc(countw(&amp;amp;months.,' '));
%do month_ind=1 %to &amp;amp;months_count.;
	%let yyyymm = %scan(&amp;amp;months.,&amp;amp;month_ind.,' ');
	%let yymm=%substr(&amp;amp;yyyymm.,3,4);
	%let year=%substr(&amp;amp;yyyymm.,1,4);
	%let month=%substr(&amp;amp;yyyymm.,5,2);

	%put &amp;amp;=yyyymm.;
	%put &amp;amp;=yymm.;
	%put &amp;amp;=year.;
	%put &amp;amp;=month.;


%let end_date = %sysfunc(intnx(month,%sysfunc(today()),-51,end), date9.);

%put &amp;amp;=end_date;

libname kc&amp;amp;yymm.  "/sas/Prod/Data/&amp;amp;yyyymm.";

data logic_&amp;amp;yymm.;
set kc&amp;amp;yymm..dec_data;
if date ne . and date &amp;lt;= "&amp;amp;end_date"d then IND = 1;
else IND = 0;
run;


%end;

%mend;
%check(201701 201702 201703 201704 201705 201706 201707 201708 201709 201710 201711 201712);

&lt;/PRE&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;vnreddy&lt;/P&gt;</description>
    <pubDate>Wed, 12 May 2021 21:31:57 GMT</pubDate>
    <dc:creator>vnreddy</dc:creator>
    <dc:date>2021-05-12T21:31:57Z</dc:date>
    <item>
      <title>Dynamic last dat of the month using year and month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-last-dat-of-the-month-using-year-and-month/m-p/740972#M231561</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am having difficulty in creating a dynamic last day of the month date9. format by using yyyymm format.&lt;/P&gt;
&lt;P&gt;I have created below code, and&amp;nbsp;at present &amp;nbsp;i am manually changing end_date value (e.g., -51, -52, so on). I want to eliminate this and macro should pick the last day of the month&amp;nbsp;from %check(201701 201702)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;end_date values in &lt;STRONG&gt;dec_data&lt;/STRONG&gt; dataset will in 03JAN2017, 10JAN2017, 31JAN2017 so on&amp;nbsp;format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;

%macro check(months);

%let months_count = %sysfunc(countw(&amp;amp;months.,' '));
%do month_ind=1 %to &amp;amp;months_count.;
	%let yyyymm = %scan(&amp;amp;months.,&amp;amp;month_ind.,' ');
	%let yymm=%substr(&amp;amp;yyyymm.,3,4);
	%let year=%substr(&amp;amp;yyyymm.,1,4);
	%let month=%substr(&amp;amp;yyyymm.,5,2);

	%put &amp;amp;=yyyymm.;
	%put &amp;amp;=yymm.;
	%put &amp;amp;=year.;
	%put &amp;amp;=month.;


%let end_date = %sysfunc(intnx(month,%sysfunc(today()),-51,end), date9.);

%put &amp;amp;=end_date;

libname kc&amp;amp;yymm.  "/sas/Prod/Data/&amp;amp;yyyymm.";

data logic_&amp;amp;yymm.;
set kc&amp;amp;yymm..dec_data;
if date ne . and date &amp;lt;= "&amp;amp;end_date"d then IND = 1;
else IND = 0;
run;


%end;

%mend;
%check(201701 201702 201703 201704 201705 201706 201707 201708 201709 201710 201711 201712);

&lt;/PRE&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;vnreddy&lt;/P&gt;</description>
      <pubDate>Wed, 12 May 2021 21:31:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-last-dat-of-the-month-using-year-and-month/m-p/740972#M231561</guid>
      <dc:creator>vnreddy</dc:creator>
      <dc:date>2021-05-12T21:31:57Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic last dat of the month using year and month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-last-dat-of-the-month-using-year-and-month/m-p/740975#M231563</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;I want to eliminate this and macro should pick the last day of the month&amp;nbsp;from %check(201701 201702)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;end_date values in &lt;STRONG&gt;dec_data&lt;/STRONG&gt; dataset will in 03JAN2017, 10JAN2017, 31JAN2017 so on&amp;nbsp;format.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is confusing. You talk about months, then show week end dates. Please explain.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 May 2021 22:16:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-last-dat-of-the-month-using-year-and-month/m-p/740975#M231563</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-05-12T22:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic last dat of the month using year and month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-last-dat-of-the-month-using-year-and-month/m-p/740977#M231565</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/301412"&gt;@vnreddy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am having difficulty in creating a dynamic last day of the month date9. format by using yyyymm format.&lt;/P&gt;
&lt;P&gt;I have created below code, and&amp;nbsp;at present &amp;nbsp;i am manually changing end_date value (e.g., -51, -52, so on). I want to eliminate this and macro should pick the last day of the month&amp;nbsp;from %check(201701 201702)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;end_date values in &lt;STRONG&gt;dec_data&lt;/STRONG&gt; dataset will in 03JAN2017, 10JAN2017, 31JAN2017 so on&amp;nbsp;format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;
%macro check(months);

%let months_count = %sysfunc(countw(&amp;amp;months.,' '));
%do month_ind=1 %to &amp;amp;months_count.;
	%let yyyymm = %scan(&amp;amp;months.,&amp;amp;month_ind.,' ');
	%let yymm=%substr(&amp;amp;yyyymm.,3,4);
	%let year=%substr(&amp;amp;yyyymm.,1,4);
	%let month=%substr(&amp;amp;yyyymm.,5,2);

	%put &amp;amp;=yyyymm.;
	%put &amp;amp;=yymm.;
	%put &amp;amp;=year.;
	%put &amp;amp;=month.;


%let end_date = %sysfunc(intnx(month,%sysfunc(today()),-51,end), date9.);

%put &amp;amp;=end_date;

libname kc&amp;amp;yymm.  "/sas/Prod/Data/&amp;amp;yyyymm.";

data logic_&amp;amp;yymm.;
set kc&amp;amp;yymm..dec_data;
if date ne . and date &amp;lt;= "&amp;amp;end_date"d then IND = 1;
else IND = 0;
run;


%end;

%mend;
%check(201701 201702 201703 201704 201705 201706 201707 201708 201709 201710 201711 201712);

&lt;/PRE&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;vnreddy&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not sure if this is exactly what you are looking for, just the end_date bit as I have no clue what you data set looks like.&lt;/P&gt;
&lt;PRE&gt;%macro check(months);

%let months_count = %sysfunc(countw(&amp;amp;months.,' '));
%do month_ind=1 %to &amp;amp;months_count.;
	%let yyyymm = %sysfunc(inputn(%scan(&amp;amp;months.,&amp;amp;month_ind.,' '),yymmn6.));

%let end_date = %sysfunc(intnx(month,&amp;amp;yyyymm.,0,end), date9.);

%put end_date for %scan(&amp;amp;months.,&amp;amp;month_ind.,' ') is: &amp;amp;end_date.;

%end;

%mend;
%check(201701 201702 201703 201704 201705 201706 201707 201708 201709 201710 201711 201712);
&lt;/PRE&gt;
&lt;P&gt;Generally if you are going to use a value in comparisons it is often better not to format the value, i.e. the "&amp;amp;end_date."d but use the unformatted number &amp;amp;end_date. and leave off the ", date9." when creating it.&lt;/P&gt;</description>
      <pubDate>Wed, 12 May 2021 22:12:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-last-dat-of-the-month-using-year-and-month/m-p/740977#M231565</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-12T22:12:15Z</dc:date>
    </item>
  </channel>
</rss>

