<?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: How to write macro to extract latest months dataset in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-write-macro-to-extract-latest-months-dataset/m-p/300302#M60514</link>
    <description>&lt;P&gt;First yo need a way to get a specific (the prior month initially).&lt;/P&gt;
&lt;P&gt;This is accomplished with the INTNX function, which you could call from a data step, or via %sysfunc in open code/macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The you need to verify that the specific month data&amp;nbsp;set exists.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here you got a lot of options, like DICTIONARY.TABLES in SQ, SASHELP.VSTABLE from other SAS programs, data step SAS file &amp;nbsp;functions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the specific month doesn't exist, you need to adjust the month with INTNX again. Depending on the how dynamic&amp;nbsp;you wish to this, us %IF %THEN %ELSE logic, or some kind of loop logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This would get you started, get back when you specific questions a long the way.&lt;/P&gt;</description>
    <pubDate>Fri, 23 Sep 2016 08:30:03 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2016-09-23T08:30:03Z</dc:date>
    <item>
      <title>How to write macro to extract latest months dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-write-macro-to-extract-latest-months-dataset/m-p/300298#M60513</link>
      <description>There are multiple datasets with name data_yyyymm format but now I want to extract latest month data set by writing macro how can I do. Example if I'm running macro in September I'll be having August dataset which I need extract some time August month dataset not available in that case macro need to extract July month dataset.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 23 Sep 2016 08:12:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-write-macro-to-extract-latest-months-dataset/m-p/300298#M60513</guid>
      <dc:creator>Ravikumarpa4</dc:creator>
      <dc:date>2016-09-23T08:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to write macro to extract latest months dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-write-macro-to-extract-latest-months-dataset/m-p/300302#M60514</link>
      <description>&lt;P&gt;First yo need a way to get a specific (the prior month initially).&lt;/P&gt;
&lt;P&gt;This is accomplished with the INTNX function, which you could call from a data step, or via %sysfunc in open code/macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The you need to verify that the specific month data&amp;nbsp;set exists.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here you got a lot of options, like DICTIONARY.TABLES in SQ, SASHELP.VSTABLE from other SAS programs, data step SAS file &amp;nbsp;functions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the specific month doesn't exist, you need to adjust the month with INTNX again. Depending on the how dynamic&amp;nbsp;you wish to this, us %IF %THEN %ELSE logic, or some kind of loop logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This would get you started, get back when you specific questions a long the way.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Sep 2016 08:30:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-write-macro-to-extract-latest-months-dataset/m-p/300302#M60514</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-09-23T08:30:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to write macro to extract latest months dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-write-macro-to-extract-latest-months-dataset/m-p/300304#M60515</link>
      <description>&lt;PRE&gt;

No need Macro.


data data_201608;
set sashelp.class;
run;
data data_201609;
set sashelp.class;
run;




proc sql;
select memname into : want 
 from dictionary.members
  having libname='WORK' and memtype='DATA' 
   and input(scan(memname,-1,'_'),best.)=
       max(input(scan(memname,-1,'_'),best.));
quit;

%put &amp;amp;want ;

&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Sep 2016 08:40:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-write-macro-to-extract-latest-months-dataset/m-p/300304#M60515</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-09-23T08:40:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to write macro to extract latest months dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-write-macro-to-extract-latest-months-dataset/m-p/300306#M60516</link>
      <description>&lt;P&gt;Why do you have data in the dataset name? &amp;nbsp;Now this isn't necessarily you, it seems that quite a few people insist on putting date information in dataset names, but it is the direct cause of making you have this type of problem. &amp;nbsp;Use one large dataset with a variable for date, this then trivialises the problem as code can be written for the one structure/name, and subsetting is simply where clausing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As for coding:&lt;/P&gt;
&lt;PRE&gt;data xyz_201406;
  a=1;
run;
data xyz_201405;
  a=2;
run;
data tmp;
  set sashelp.vtable (where=(libname="WORK" and substr(memname,1,3)="XYZ"));
  dt=scan(memname,2,"_");
run;
proc sort data=tmp;
  by dt;
run;&lt;/PRE&gt;
&lt;P&gt;This shows how you can use the sashelp tables to identify certain datasets, however it is still patching the actual problem of file setup.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Sep 2016 08:49:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-write-macro-to-extract-latest-months-dataset/m-p/300306#M60516</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-09-23T08:49:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to write macro to extract latest months dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-write-macro-to-extract-latest-months-dataset/m-p/300574#M60537</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let Run_Date = %sysfunc(today());
%let Last_Month = %sysfunc(intnx(MONTH, &amp;amp;Run_Date, -1), yymmn6.);

data want;
  set have_&amp;amp;Last_Month;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By adding the two macro statements to the top of your program, the last month macro variable suffix can be used on any dataset that follows.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Sep 2016 00:09:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-write-macro-to-extract-latest-months-dataset/m-p/300574#M60537</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2016-09-25T00:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to write macro to extract latest months dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-write-macro-to-extract-latest-months-dataset/m-p/300732#M60544</link>
      <description>Hi Team,&lt;BR /&gt;&lt;BR /&gt;Can you give me the code.&lt;BR /&gt;&lt;BR /&gt;Example in particular library I have many datasets but I wanted to know&lt;BR /&gt;latest dataset so I want to write macro for the same.&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;Ravikumar&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Simple formatting, no&lt;BR /&gt;attachments. -##</description>
      <pubDate>Mon, 26 Sep 2016 10:54:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-write-macro-to-extract-latest-months-dataset/m-p/300732#M60544</guid>
      <dc:creator>Ravikumarpa4</dc:creator>
      <dc:date>2016-09-26T10:54:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to write macro to extract latest months dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-write-macro-to-extract-latest-months-dataset/m-p/301852#M60658</link>
      <description>&lt;P&gt;I did give you some code to try. Have you tried it?&lt;/P&gt;</description>
      <pubDate>Sat, 01 Oct 2016 00:20:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-write-macro-to-extract-latest-months-dataset/m-p/301852#M60658</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2016-10-01T00:20:44Z</dc:date>
    </item>
  </channel>
</rss>

