<?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: dates issue in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805817#M317435</link>
    <description>&lt;P&gt;what do you mean by mmyy format, I tried with 1219 and got missing for month&lt;/P&gt;</description>
    <pubDate>Mon, 04 Apr 2022 09:49:36 GMT</pubDate>
    <dc:creator>HeatherNewton</dc:creator>
    <dc:date>2022-04-04T09:49:36Z</dc:date>
    <item>
      <title>dates issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/804968#M317052</link>
      <description>&lt;P&gt;I am trying to make sense of the code. but got nowhere. please help.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;month=(input(years,4.)-int(input(years,4.)/100)*100)*12 +int(input(years,4.)/100);
what is the above doing? I tried with different value for "years" and got nowhere.

eg.
data new;
years=1961;
month=(input(years,4.)-int(input(years,4.)/100)*100)*12 +int(input(years,4.)/100);
run;

only getting '.' i.e. missing
for month


&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Mar 2022 06:45:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/804968#M317052</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-03-30T06:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: dates issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/804975#M317056</link>
      <description>&lt;P&gt;The INPUT function with a numeric informat is used to read numeric data from a character argument. In your code, years is a numeric variable, so SAS first has to convert this to a character value. This automatic conversion uses the BEST12. format, so the result of the conversion is&lt;/P&gt;
&lt;PRE&gt;"        1961"&lt;/PRE&gt;
&lt;P&gt;The INPUT then reads the first 4 characters (which are all blanks), so you get a missing value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maxim 3: Know Your Data.&lt;/P&gt;
&lt;P&gt;Inspect the input dataset of the original step from which you took the assignment to see the definition of variable years.&lt;/P&gt;
&lt;P&gt;If the variable is created in that step, show the code that does it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could it be that the formula is designed to count months from a MMYY value:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input years $4.;
month=(input(years,4.)-int(input(years,4.)/100)*100)*12 +int(input(years,4.)/100);
datalines;
0000
0100
0001
0101
0201
0002
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Mar 2022 07:09:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/804975#M317056</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-30T07:09:17Z</dc:date>
    </item>
    <item>
      <title>Re: dates issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805080#M317088</link>
      <description>&lt;P&gt;My &lt;STRONG&gt;guess&lt;/STRONG&gt; is that someone had a value that was a duration measured in years, such as 12, and was character value for some reason, and wanted to estimate a duration in months.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the INPUT requires CHARACTER values so of course your test with years=1961; does nothing as years here would be numeric. The implied conversion to character and appears in your LOG, which uses the BEST12. format, for input would have about 8 leading blanks. So the input reads 4 of those blanks and gets a missing result. So the result of all those inputs is missing and no calculation actually performed.&lt;/P&gt;
&lt;PRE&gt;data new;
years="10.2";
month=(input(years,4.)-int(input(years,4.)/100)*100)*12 +int(input(years,4.)/100);
run;&lt;/PRE&gt;
&lt;P&gt;Returns a value of 122.4 months.&lt;/P&gt;
&lt;P&gt;The Int function returns the integer portion of a result so the int(input(years,4.)/100) removes the decimal from the division so that the remainder of the middle term turns a "whole month" number of some sort.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Important learning point: When &lt;STRONG&gt;you &lt;/STRONG&gt;write code that is obscure like this &lt;STRONG&gt;you&lt;/STRONG&gt; should include a comment as to what it does and why it was needed.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2022 14:43:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805080#M317088</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-30T14:43:51Z</dc:date>
    </item>
    <item>
      <title>Re: dates issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805085#M317093</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/416388"&gt;@HeatherNewton&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;another learning point ... if you were to write such code (or similar) in the future, use actual SAS date values (or actual SAS date time values) and functions such as INTCK and INTNX to determine dates (for example, what date is 15 months previous?) (for example, what date is 100 days previous?), rather than this complicated mathematical formula that is difficult to understand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In addition SAS has done the hard work of creating calendar functions that takes into account leap years, months of unequal number of days, and so on, and then tested and debugged these functions so we have confidence that they work properly, so you don't have to create your own functions to account for these things (and possibly get it wrong in your program).&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2022 15:04:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805085#M317093</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-30T15:04:23Z</dc:date>
    </item>
    <item>
      <title>Re: dates issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805686#M317380</link>
      <description>&lt;P&gt;I have confirmed that the years is actually no of years. could you please check what is the significance of this calculation of month.. I see no difference with just applying *12 to no of years whether the no of years is integer or with decimal&lt;/P&gt;
&lt;PRE&gt;data result;
input YEARS_OF_IMP $5.;  
month=(input(YEARS_OF_IMP,4.)-int(input(YEARS_OF_IMP,4.)/100)*100)*12 +int(input(YEARS_OF_IMP,4.)/100);  
X=input(YEARS_OF_IMP,4.);  
 
month1 = (X-(int(X/100))*100)*12+int(X/100); 
test2=int(X/100);  
test2a=int(X/100)*100;  
test3=X-int(X/100)*100;  
test3a=(X-int(X/100)*100)*12;   
 
datalines;  
0 
20 
30 
15.5 
12.8 
12.3 
14.1 
; 
 
proc print data=result; &lt;/PRE&gt;</description>
      <pubDate>Sun, 03 Apr 2022 08:08:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805686#M317380</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-04-03T08:08:42Z</dc:date>
    </item>
    <item>
      <title>Re: dates issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805687#M317381</link>
      <description>&lt;P&gt;Look at the variable in the dataset to which this formula is applied. Knowing the data (Maxim 3) is essential in getting a grasp on the logic behind it, and finding ways to get the same result in a way that is easier to understand and maintain.&lt;/P&gt;
&lt;P&gt;So go back to the program where you encountered this, and look at the dataset that is used.&lt;/P&gt;</description>
      <pubDate>Sun, 03 Apr 2022 08:14:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805687#M317381</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-03T08:14:39Z</dc:date>
    </item>
    <item>
      <title>Re: dates issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805741#M317391</link>
      <description>I did. The data set is no of years. The calculation not seems not doing mich. What do u think?</description>
      <pubDate>Sun, 03 Apr 2022 19:29:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805741#M317391</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-04-03T19:29:10Z</dc:date>
    </item>
    <item>
      <title>Re: dates issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805743#M317392</link>
      <description>&lt;P&gt;Please post an example of your data in a&amp;nbsp;&lt;U&gt;data step with datalines&lt;/U&gt;, so we have something to test the code against.&lt;/P&gt;</description>
      <pubDate>Sun, 03 Apr 2022 19:35:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805743#M317392</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-03T19:35:40Z</dc:date>
    </item>
    <item>
      <title>Re: dates issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805757#M317400</link>
      <description>I did yesterday. Could u see?</description>
      <pubDate>Sun, 03 Apr 2022 23:11:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805757#M317400</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-04-03T23:11:22Z</dc:date>
    </item>
    <item>
      <title>Re: dates issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805758#M317401</link>
      <description>data result;&lt;BR /&gt;input YEARS_OF_IMP $5.;  &lt;BR /&gt;month=(input(YEARS_OF_IMP,4.)-int(input(YEARS_OF_IMP,4.)/100)*100)*12 +int(input(YEARS_OF_IMP,4.)/100);  &lt;BR /&gt;X=input(YEARS_OF_IMP,4.);  &lt;BR /&gt; &lt;BR /&gt;month1 = (X-(int(X/100))*100)*12+int(X/100); &lt;BR /&gt;test2=int(X/100);  &lt;BR /&gt;test2a=int(X/100)*100;  &lt;BR /&gt;test3=X-int(X/100)*100;  &lt;BR /&gt;test3a=(X-int(X/100)*100)*12;   &lt;BR /&gt; &lt;BR /&gt;datalines;  &lt;BR /&gt;0 &lt;BR /&gt;20 &lt;BR /&gt;30 &lt;BR /&gt;15.5 &lt;BR /&gt;12.8 &lt;BR /&gt;12.3 &lt;BR /&gt;14.1 &lt;BR /&gt;; &lt;BR /&gt; &lt;BR /&gt;proc print data=result;</description>
      <pubDate>Sun, 03 Apr 2022 23:14:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805758#M317401</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-04-03T23:14:06Z</dc:date>
    </item>
    <item>
      <title>Re: dates issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805759#M317402</link>
      <description>Just posted sgsin</description>
      <pubDate>Sun, 03 Apr 2022 23:14:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805759#M317402</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-04-03T23:14:31Z</dc:date>
    </item>
    <item>
      <title>Re: dates issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805787#M317415</link>
      <description>&lt;P&gt;Are these actual, &lt;STRONG&gt;real&lt;/STRONG&gt; values you took from your dataset? I ask because from a second look I am now VERY sure that the formula is designed to calculate a number of months from a 4-digit integer that is written in a MMYY format:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;month =
  (
    input(YEARS_OF_IMP,4.)
    -
    int(
      input(YEARS_OF_IMP,4.) / 100
    )  *  100 /* subtract the left two digits (100 and 1000 order of magnitude) from the number */
  ) * 12 /* and multiply the remaining by 12, indicating that this is a year number */
  +
  int(
    input(YEARS_OF_IMP,4.) / 100
  ) /* and add the first two digits, so these are the months */
; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;An input with a fraction makes no sense in this context.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 06:40:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805787#M317415</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-04T06:40:44Z</dc:date>
    </item>
    <item>
      <title>Re: dates issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805815#M317434</link>
      <description>&lt;P&gt;yes the user only provide data of 0,20,30&lt;/P&gt;
&lt;P&gt;let me ask them again&lt;/P&gt;
&lt;P&gt;why are you sure it is mmyy format ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 09:46:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805815#M317434</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-04-04T09:46:19Z</dc:date>
    </item>
    <item>
      <title>Re: dates issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805817#M317435</link>
      <description>&lt;P&gt;what do you mean by mmyy format, I tried with 1219 and got missing for month&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 09:49:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805817#M317435</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-04-04T09:49:36Z</dc:date>
    </item>
    <item>
      <title>Re: dates issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805828#M317442</link>
      <description>&lt;P&gt;Can't be:&lt;/P&gt;
&lt;PRE&gt; 69         data _null_;
 70         years_of_imp = "1219";
 71         month =
 72           (
 73             input(YEARS_OF_IMP,4.)
 74             -
 75             int(
 76               input(YEARS_OF_IMP,4.) / 100
 77             )  *  100 /* subtract the left two digits (100 and 1000 order of magnitude) from the number */
 78           ) * 12 /* and multiply the remaining by 12, indicating that this is a year number */
 79           +
 80           int(
 81             input(YEARS_OF_IMP,4.) / 100
 82           ) /* and add the first two digits, so these are the months */
 83         ;
 84         put month=;
 85         run;
 
 month=240
&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Apr 2022 11:03:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805828#M317442</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-04T11:03:00Z</dc:date>
    </item>
    <item>
      <title>Re: dates issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805831#M317444</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/416388"&gt;@HeatherNewton&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;why are you sure it is mmyy format ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;See my dissection of the formula.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 11:29:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/805831#M317444</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-04T11:29:53Z</dc:date>
    </item>
    <item>
      <title>Re: dates issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/806236#M317617</link>
      <description>&lt;P&gt;but 240 mean the no of month from 1219 to when? I still dont get the logic after I tried a few more&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1219&amp;nbsp; &amp;nbsp; 240 months&lt;/P&gt;
&lt;P&gt;1021&amp;nbsp; &amp;nbsp; 262 months&lt;/P&gt;
&lt;P&gt;1217&amp;nbsp; &amp;nbsp; 216 months&lt;/P&gt;
&lt;P&gt;1221&amp;nbsp; &amp;nbsp;264 months&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 09:56:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/806236#M317617</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-04-06T09:56:04Z</dc:date>
    </item>
    <item>
      <title>Re: dates issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/806242#M317620</link>
      <description>&lt;P&gt;Consider the start of 2000 as the "zero" point, so January of 2000 is month #1. Then this makes sense:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data result;
input YEARS_OF_IMP $5.; 
month =
  (
    input(YEARS_OF_IMP,4.)
    -
    int(
      input(YEARS_OF_IMP,4.) / 100
    )  *  100 /* subtract the left two digits (100 and 1000 order of magnitude) from the number */
  ) * 12 /* and multiply the remaining by 12, indicating that this is a year number */
  +
  int(
    input(YEARS_OF_IMP,4.) / 100
  ) /* and add the first two digits, so these are the months */
;
datalines;
0100
0200
0101
0422
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You will get results of 1, 2,13 and 268. April 2022 is the 268th month after December 1999.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TBH, someone who writes such a formula into code, without leaving proper documentation (or at least a comment in the code) that details the function and intent, should be hung, drawn and quartered. Or at least have their behind paddled in front of the whole department. Let this be a lesson to yourself: whenever you have to write code that is not immediately understandable at first glance, write a comment to explain what happens. Also do that whenever you are forced to write code that causes a non-standard NOTE (like "More than one datasets has repeating BY values" in a MERGE)&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 10:20:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-issue/m-p/806242#M317620</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-06T10:20:24Z</dc:date>
    </item>
  </channel>
</rss>

