<?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: choose latest 6 months of dates as variables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/choose-latest-6-months-of-dates-as-variables/m-p/180763#M46051</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's a simple way, not the most efficient but easy to follow and easy to modify:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I create 1 macro variables that contain the names of the months of interest that can then be used in a keep statement in another data step. You can tweak the start date and the count intervals as needed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let start_date=&amp;amp;sysdate;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put &amp;amp;start_date;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data temp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i=1 to 6;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; date=intnx('month', "&amp;amp;start_date"d, -1*i);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; date_formatted=put(date, monyy7.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select date_formatted&amp;nbsp; into :keep_date_var separated by " "&lt;/P&gt;&lt;P&gt;from temp;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put &amp;amp;keep_date_var;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;keep id &amp;amp;keep_date_var;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 23 Dec 2013 17:11:48 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2013-12-23T17:11:48Z</dc:date>
    <item>
      <title>choose latest 6 months of dates as variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/choose-latest-6-months-of-dates-as-variables/m-p/180762#M46050</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&amp;nbsp; I have a dataset with Dates as variables (Eg. Jan2008, Feb2008, Mar2008..... Oct2013, Nov2013)... how in SAS can I pick only the latest 6 months? so in this case only Jun2013 to Nov2013 .. I'm asking this becasue I want to automate it, and not change the months every month.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Dec 2013 16:30:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/choose-latest-6-months-of-dates-as-variables/m-p/180762#M46050</guid>
      <dc:creator>podarum</dc:creator>
      <dc:date>2013-12-23T16:30:24Z</dc:date>
    </item>
    <item>
      <title>Re: choose latest 6 months of dates as variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/choose-latest-6-months-of-dates-as-variables/m-p/180763#M46051</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's a simple way, not the most efficient but easy to follow and easy to modify:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I create 1 macro variables that contain the names of the months of interest that can then be used in a keep statement in another data step. You can tweak the start date and the count intervals as needed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let start_date=&amp;amp;sysdate;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put &amp;amp;start_date;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data temp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i=1 to 6;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; date=intnx('month', "&amp;amp;start_date"d, -1*i);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; date_formatted=put(date, monyy7.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select date_formatted&amp;nbsp; into :keep_date_var separated by " "&lt;/P&gt;&lt;P&gt;from temp;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put &amp;amp;keep_date_var;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;keep id &amp;amp;keep_date_var;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Dec 2013 17:11:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/choose-latest-6-months-of-dates-as-variables/m-p/180763#M46051</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-12-23T17:11:48Z</dc:date>
    </item>
    <item>
      <title>Re: choose latest 6 months of dates as variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/choose-latest-6-months-of-dates-as-variables/m-p/180764#M46052</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I first off would suggest not having a dataset with months as variables.&amp;nbsp; Store it in normalized form with months as rows.&amp;nbsp; Then you can easily select the last 6 months' worth of data using a WHERE or subsetting IF statement, and if needed transpose back.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you must keep it in horizontal format, you could select the variable names from dictionary.columns (or proc contents output) into a macro variable.&amp;nbsp; Substitute proper names for LIBNAME and MEMNAME below (MEMNAME = dataset name).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select name into :collist separated by ' '&lt;/P&gt;&lt;P&gt;from dictionary.columns&lt;/P&gt;&lt;P&gt;where libname='WORK' and memname='HAVE'&lt;/P&gt;&lt;P&gt;and input(name,MONYY.) ge intnx('Month','01NOV2013'd,-5); *you can easily adjust this to be programmatic, not sure what your conditions are for determining 'last month' - use INTNX to pick last 6 months once you have that defined [macro variable, last actual calendar month, etc.];&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;keep &amp;amp;colllist.; *and any other needed variables.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Dec 2013 17:15:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/choose-latest-6-months-of-dates-as-variables/m-p/180764#M46052</guid>
      <dc:creator>snoopy369</dc:creator>
      <dc:date>2013-12-23T17:15:09Z</dc:date>
    </item>
    <item>
      <title>Re: choose latest 6 months of dates as variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/choose-latest-6-months-of-dates-as-variables/m-p/180765#M46053</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Great help.. thanks to alll&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Dec 2013 18:34:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/choose-latest-6-months-of-dates-as-variables/m-p/180765#M46053</guid>
      <dc:creator>podarum</dc:creator>
      <dc:date>2013-12-23T18:34:27Z</dc:date>
    </item>
  </channel>
</rss>

