<?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: Reading a date field and creating a MONTH variable. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-date-field-and-creating-a-MONTH-variable/m-p/443023#M110806</link>
    <description>&lt;P&gt;You can use the INTCK function to count the months between two dates.&amp;nbsp; So all you need is the date of the first record (retained across all observations) and date of the N'th record:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_:);
  input @25 date ddmmyy6.;
  format date date9.;
  if _n_=1 then _first_date=date;
  retain _first_date;
  month=1+intck('month',date,_first_date);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 06 Mar 2018 20:10:38 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2018-03-06T20:10:38Z</dc:date>
    <item>
      <title>Reading a date field and creating a MONTH variable.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-date-field-and-creating-a-MONTH-variable/m-p/442990#M110797</link>
      <description>&lt;P&gt;Hi All, Need a help. I have a flat where on 25th position, I have a date value of DDMMYY6. (or can be read as character as well). Now, the data is stacked on a daily basis in this file. So, first 100 records will have lets say 160218 (16th Feb 2018 i.e. DAY 1) populated in 25th column onwards for 6 positions. From 101th records, DAY 2 starts i.e. column 25 to column 30 will have 150218, so on and so forth. When we will go to the last record, we will have lets say 270817.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to write a code which will read this date values and will create a MONTH_VAL variables regardless of what is the starting date in record 1 and what is the final date in this file. So, it will read month and year value and assign month_val accordingly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data is will have this date value in descending order i.e. highest dates will appear in the first set of records.&lt;/P&gt;
&lt;P&gt;So, my code will read all other values based on different offset positions in the file plus:&lt;/P&gt;
&lt;P&gt;MONTH_VAL will be 1 for 160218&lt;/P&gt;
&lt;P&gt;MONTH_VAL will be&amp;nbsp;1 for 150218&lt;/P&gt;
&lt;P&gt;MONTH_VAL will be&amp;nbsp;1 for&amp;nbsp;140218&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;MONTH_VAL will be 2 for 310118&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;MONTH_VAL will be 7 for 270817&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;this file removes weekends/bank holidays anyways, so that is not a concern.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please can someone share the logic how can I derive this MONTH_VAL&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;MONTH_VAL will be lets say 270817&lt;/P&gt;</description>
      <pubDate>Tue, 06 Mar 2018 18:30:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-date-field-and-creating-a-MONTH-variable/m-p/442990#M110797</guid>
      <dc:creator>tapas_16880</dc:creator>
      <dc:date>2018-03-06T18:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a date field and creating a MONTH variable.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-date-field-and-creating-a-MONTH-variable/m-p/442998#M110800</link>
      <description>&lt;P&gt;You do need to learn about how SAS handles dates.&amp;nbsp; However, that can be postponed here.&amp;nbsp; Your question can be answered based on the months and years in your existing data while ignoring the actual date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you read in the data, part of your INPUT statement can be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;input m 27-28 y 29-30;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can compute MONTH_VAL based on M and Y.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if _n_=1 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; first_m = m;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; first_y = y;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; retain first_m first_y;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;month_val = (1 + first_m - m) + 12 * (first_y - y);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This assumes that you want MONTH_VAL=1 for whatever date is first in your data.&amp;nbsp; (If you want MONTH_VAL=1 to always correspond to February 2018, the code becomes much simpler.)&lt;/P&gt;</description>
      <pubDate>Tue, 06 Mar 2018 18:28:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-date-field-and-creating-a-MONTH-variable/m-p/442998#M110800</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-03-06T18:28:26Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a date field and creating a MONTH variable.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-date-field-and-creating-a-MONTH-variable/m-p/443001#M110801</link>
      <description>&lt;P&gt;MONTH_VAL = 1 will not always correspond to Feb 2018. It will be 1 based on whatever date is in the first set of records.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Mar 2018 18:33:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-date-field-and-creating-a-MONTH-variable/m-p/443001#M110801</guid>
      <dc:creator>tapas_16880</dc:creator>
      <dc:date>2018-03-06T18:33:24Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a date field and creating a MONTH variable.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-a-date-field-and-creating-a-MONTH-variable/m-p/443023#M110806</link>
      <description>&lt;P&gt;You can use the INTCK function to count the months between two dates.&amp;nbsp; So all you need is the date of the first record (retained across all observations) and date of the N'th record:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_:);
  input @25 date ddmmyy6.;
  format date date9.;
  if _n_=1 then _first_date=date;
  retain _first_date;
  month=1+intck('month',date,_first_date);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Mar 2018 20:10:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-a-date-field-and-creating-a-MONTH-variable/m-p/443023#M110806</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-03-06T20:10:38Z</dc:date>
    </item>
  </channel>
</rss>

