<?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: Year and month in a production process. Help needed. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Year-and-month-in-a-production-process-Help-needed/m-p/330673#M74230</link>
    <description>&lt;P&gt;&amp;lt;Rant on&amp;gt;&lt;/P&gt;
&lt;P&gt;Did NO ONE pay attention to Y2k? Yet again we have 2 digit years just waiting to be a problem&lt;/P&gt;
&lt;P&gt;&amp;lt;/Rant off&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Example 1: Verifying the Existence of a Data Set 
This example verifies the existence of a data set. If the data set does not exist, then the example displays a message in the log: 

%let dsname=sasuser.houses;
%macro opends(name);
%if %sysfunc(exist(&amp;amp;name)) %then
   %let dsid=%sysfunc(open(&amp;amp;name,i));
%else %put Data set &amp;amp;name does not exist.;
%mend opends;
%opends(&amp;amp;dsname);
&lt;/PRE&gt;
&lt;P&gt;One question: How are you getting the date to base "previous" on?.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you have an actual date value to look for (INTNX) then use the formatted value for that date using a YYMMn4. format.&lt;/P&gt;</description>
    <pubDate>Wed, 08 Feb 2017 00:05:52 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-02-08T00:05:52Z</dc:date>
    <item>
      <title>Year and month in a production process. Help needed.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Year-and-month-in-a-production-process-Help-needed/m-p/330664#M74227</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a process that uses previous months data for the current month's run. How can I check if the data set for previous month is avaialble?&lt;/P&gt;
&lt;P&gt;Required data set is named in this format: File1612 &amp;nbsp;othewise File&amp;lt;2 digit year&amp;gt;&amp;lt;2 digit month&amp;gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I check the existance of the file in the begining of a month and also the begining of a new year?&lt;/P&gt;
&lt;P&gt;(If I dont check the year part in the begining of a new year then it will read last years data)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please let me know.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 23:50:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Year-and-month-in-a-production-process-Help-needed/m-p/330664#M74227</guid>
      <dc:creator>renjithr</dc:creator>
      <dc:date>2017-02-07T23:50:11Z</dc:date>
    </item>
    <item>
      <title>Re: Year and month in a production process. Help needed.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Year-and-month-in-a-production-process-Help-needed/m-p/330668#M74228</link>
      <description>&lt;P&gt;INTNX allows you to increment a date.&lt;/P&gt;
&lt;P&gt;Format it according to what you need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check for existence of a dataset:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/kb/24/670.html" target="_blank"&gt;http://support.sas.com/kb/24/670.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 23:57:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Year-and-month-in-a-production-process-Help-needed/m-p/330668#M74228</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-07T23:57:05Z</dc:date>
    </item>
    <item>
      <title>Re: Year and month in a production process. Help needed.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Year-and-month-in-a-production-process-Help-needed/m-p/330673#M74230</link>
      <description>&lt;P&gt;&amp;lt;Rant on&amp;gt;&lt;/P&gt;
&lt;P&gt;Did NO ONE pay attention to Y2k? Yet again we have 2 digit years just waiting to be a problem&lt;/P&gt;
&lt;P&gt;&amp;lt;/Rant off&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Example 1: Verifying the Existence of a Data Set 
This example verifies the existence of a data set. If the data set does not exist, then the example displays a message in the log: 

%let dsname=sasuser.houses;
%macro opends(name);
%if %sysfunc(exist(&amp;amp;name)) %then
   %let dsid=%sysfunc(open(&amp;amp;name,i));
%else %put Data set &amp;amp;name does not exist.;
%mend opends;
%opends(&amp;amp;dsname);
&lt;/PRE&gt;
&lt;P&gt;One question: How are you getting the date to base "previous" on?.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you have an actual date value to look for (INTNX) then use the formatted value for that date using a YYMMn4. format.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 00:05:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Year-and-month-in-a-production-process-Help-needed/m-p/330673#M74230</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-02-08T00:05:52Z</dc:date>
    </item>
    <item>
      <title>Re: Year and month in a production process. Help needed.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Year-and-month-in-a-production-process-Help-needed/m-p/330675#M74232</link>
      <description>&lt;P&gt;Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am getting the previous date as of run time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For eg: If I am running the process today then I am checking if last month's file is available.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 00:10:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Year-and-month-in-a-production-process-Help-needed/m-p/330675#M74232</guid>
      <dc:creator>renjithr</dc:creator>
      <dc:date>2017-02-08T00:10:47Z</dc:date>
    </item>
    <item>
      <title>Re: Year and month in a production process. Help needed.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Year-and-month-in-a-production-process-Help-needed/m-p/330679#M74235</link>
      <description>&lt;P&gt;This may get you started.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data _null_;
   lastmonth= intnx('month',today(),-1,'B');
   /* replace LIB in the next line with the LIBRARY
   the data sets should be in*/
   length fname $ 43;
   fname = catt('LIB.FILE',put( lastmonth, yymmn4.));
   if exist(fname) then do; 
      put 'File found' fname;
      call symputx('TargetFile',fname);
   Else put Fname ' not found';
run;

%put &amp;amp;targetfile;&lt;/PRE&gt;
&lt;P&gt;You could then use &amp;amp;targetfile whenever you need the name of that previously named data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are placing them into different libraries then it will be up to you to provide logic to find the library.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 00:32:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Year-and-month-in-a-production-process-Help-needed/m-p/330679#M74235</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-02-08T00:32:50Z</dc:date>
    </item>
    <item>
      <title>Re: Year and month in a production process. Help needed.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Year-and-month-in-a-production-process-Help-needed/m-p/330707#M74253</link>
      <description>&lt;P&gt;Thanks ballardw!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However when I run your code the&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%put &amp;amp;targetfile; &lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;is not getting resolved.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 04:00:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Year-and-month-in-a-production-process-Help-needed/m-p/330707#M74253</guid>
      <dc:creator>renjithr</dc:creator>
      <dc:date>2017-02-08T04:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: Year and month in a production process. Help needed.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Year-and-month-in-a-production-process-Help-needed/m-p/330711#M74254</link>
      <description>&lt;P&gt;I modified the code as &amp;nbsp;below but it is throwing some syntax errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options symbolgen mlogic merror;&lt;BR /&gt;%macro checkds(dsn);&lt;BR /&gt; %global f_stat_flag;&lt;/P&gt;
&lt;P&gt;%if %sysfunc(exist(&amp;amp;dsn)) %then&lt;BR /&gt; %do;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt; call symputx('f_stat_flag',1);&lt;BR /&gt; run;&lt;/P&gt;
&lt;P&gt;%end;&lt;BR /&gt; %else&lt;BR /&gt; %do;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt; call symputx('f_stat_flag',0);&lt;BR /&gt; run;&lt;/P&gt;
&lt;P&gt;%end;&lt;BR /&gt; &lt;BR /&gt;%mend checkds;&lt;BR /&gt;%checkds(&amp;amp;Target_File.);&lt;BR /&gt;%put &amp;amp;f_stat_flag.;&lt;BR /&gt;data _null_;&lt;BR /&gt; lastmonth= intnx('month',today(),-1,'B');&lt;BR /&gt; put lastmonth;&lt;BR /&gt; length fname $ 15;&lt;BR /&gt; fname = catt('cmdr.eligy',put( lastmonth, yymmn4.));&lt;BR /&gt; put fname;&lt;BR /&gt; call symputx('Target_File',fname);&lt;BR /&gt; %put &amp;amp;target_file.;&lt;BR /&gt; %checkds(&amp;amp;Target_File.);&lt;BR /&gt; if &amp;amp;f_stat_flag.='1' then&lt;BR /&gt; do;&lt;BR /&gt; put 'File found' fname;&lt;BR /&gt; END;&lt;BR /&gt; Else&lt;BR /&gt; DO;&lt;BR /&gt; put 'Previous month file not ready, so using the file prior to previous month';&lt;BR /&gt; lastmonth= intnx('month',today(),-2,'B');&lt;BR /&gt; length fname $ 43;&lt;BR /&gt; fname = catt('cmdr.eligy',put( lastmonth, yymmn4.));&lt;BR /&gt; call symputx('TargetFile',compress(fname));&lt;BR /&gt; END;&lt;BR /&gt;run;&lt;BR /&gt;%put &amp;amp;target_file.;&lt;BR /&gt;%put &amp;amp;f_stat_flag.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;eg:&amp;nbsp;&amp;nbsp;if &amp;amp;f_stat_flag.='1' then&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if &amp;amp;f_stat_flag.='1' then&lt;BR /&gt; --&lt;BR /&gt; 180&lt;BR /&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 04:24:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Year-and-month-in-a-production-process-Help-needed/m-p/330711#M74254</guid>
      <dc:creator>renjithr</dc:creator>
      <dc:date>2017-02-08T04:24:21Z</dc:date>
    </item>
    <item>
      <title>Re: Year and month in a production process. Help needed.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Year-and-month-in-a-production-process-Help-needed/m-p/330921#M74319</link>
      <description>&lt;P&gt;Please post code in a code box using the {i} icon. It gets hard to read after after the forum strips out formatting.&lt;/P&gt;
&lt;P&gt;Also, when debugging macros use the OPTION MPRINT so the error has a chance of appearing near the code that generated it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First please examine this code:&lt;/P&gt;
&lt;PRE&gt;%macro checkds(dsn);
   %global f_stat_flag;
   %let f_stat_flag= %sysfunc(exist(&amp;amp;dsn));
%mend;

%checkds(sashelp.class);  /* or other data set you know exists*/
%put &amp;amp;f_stat_flag;
%checkds(work.class);
%put &amp;amp;f_stat_flag;&lt;/PRE&gt;
&lt;P&gt;And then alternately :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro checkds2(dsn);
    %sysfunc(exist(&amp;amp;dsn))
%mend;


%put %checkds2(sashelp.class);
%put %checkds2(work.class);&lt;/PRE&gt;
&lt;P&gt;Proliferation of global macro variables is something to limit when possible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that you have two different macro variables:&lt;/P&gt;
&lt;P&gt;call symputx('Target_File',fname);&lt;/P&gt;
&lt;P&gt;call symputx('TargetFile',compress(fname));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is also absolutely no need for the checkds macro, use the FEXIST function in the data step:&lt;/P&gt;
&lt;PRE&gt;data _null_;
   lastmonth= intnx('month',today(),-1,'B');
   put lastmonth;
   length fname $ 43;
   fname = catt('cmdr.eligy',put( lastmonth, yymmn4.));
   put fname;
   if exist (fname) then  call symputx('Target_File',fname);
   Else DO;
      put 'Previous month file not ready, so using the file prior to previous month';
      lastmonth= intnx('month',today(),-2,'B');
      fname = catt('cmdr.eligy',put( lastmonth, yymmn4.));
      call symputx('TargetFile',compress(fname));
   END;
run;&lt;/PRE&gt;
&lt;P&gt;The error also is related to time of data step construction. The external macro %checkds was called when the data step was compiled not after the value of fname was constructed. Run with MPRINT and you may see some additional information.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 17:31:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Year-and-month-in-a-production-process-Help-needed/m-p/330921#M74319</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-02-08T17:31:47Z</dc:date>
    </item>
    <item>
      <title>Re: Year and month in a production process. Help needed.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Year-and-month-in-a-production-process-Help-needed/m-p/330935#M74322</link>
      <description>&lt;P&gt;Thank you so much for the solution!&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 18:32:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Year-and-month-in-a-production-process-Help-needed/m-p/330935#M74322</guid>
      <dc:creator>renjithr</dc:creator>
      <dc:date>2017-02-08T18:32:03Z</dc:date>
    </item>
  </channel>
</rss>

