<?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 do I split observations by date? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-split-observations-by-date/m-p/247796#M56339</link>
    <description>&lt;P&gt;One very powerful feature of SAS that you may not be aware of is BY group processing. If you are separating the data and intend to do the same steps to each set then the separation may not be needed. Add a YEAR variable to the data and then most procedures allow use of BY Year; to create the output for each level of the Year variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And for many actions if the date is a SAS date value (as the WANTVAR create by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/49185"&gt;@mohamed_zaki﻿&lt;/a&gt;)&amp;nbsp;you can use a format to create groups 'on the fly' for processing. A brief example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
   set have;
   wantvar=input(strip(Date_of_Service),mmddyy8.);
run;

proc means data= example max min std sum;
   class wantvar;
   format wantvar year4.;
   var Paid_amt;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;creates a summary for each year in the data.&lt;/P&gt;
&lt;P&gt;A change in format such as to YYMM or YYMON&amp;nbsp;would create a monthy summary with year information, or YYQ to get get calendar quarters.&lt;/P&gt;</description>
    <pubDate>Wed, 03 Feb 2016 16:50:23 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-02-03T16:50:23Z</dc:date>
    <item>
      <title>How do I split observations by date?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-split-observations-by-date/m-p/247625#M56325</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm very new to SAS 9.4 and just started learning to code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to separate the observations in my data by date (specifically year). My 'date_of_service' variable is in the format of mm/dd/yy but it is entered as just numbers, not as a date format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using the code below&amp;nbsp;to separate 2010 entry from 2011 entry&amp;nbsp;but SAS doesn't recognize the dates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data pei2010 pei2011;&lt;BR /&gt;set mylib.peinodup;&lt;BR /&gt;if date &amp;gt; '31Dec2010'd then output pei2011;&lt;BR /&gt;if date &amp;lt;= '31Dec2010'd then output pei2010;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I change the format for my 'date_of_service' entries&amp;nbsp;so that it can be recognized as date? When I go to column attributes, it seems like it is in character format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance and please message me if I'm missing something critical.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2016 21:58:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-split-observations-by-date/m-p/247625#M56325</guid>
      <dc:creator>jwill731</dc:creator>
      <dc:date>2016-02-02T21:58:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do I split observations by date?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-split-observations-by-date/m-p/247626#M56326</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/71482"&gt;@jwill731&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm very new to SAS 9.4 and just started learning to code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to separate the observations in my data by date (specifically year). My 'date_of_service' variable is in the format of mm/dd/yy but it is entered as just numbers, not as a date format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If it is as you said then it is recognized as Date by sas.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you run :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=mylib.peinodup;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And post the output table "Alphabetic List of Variables and Attributes" values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code should work fine also if your data is fine. But you should consider that it does not only&amp;nbsp;&lt;SPAN&gt;separate 2010 entry from 2011. But&amp;nbsp;separate (2010 and all before) from (2011 and all after).&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2016 22:10:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-split-observations-by-date/m-p/247626#M56326</guid>
      <dc:creator>mohamed_zaki</dc:creator>
      <dc:date>2016-02-02T22:10:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do I split observations by date?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-split-observations-by-date/m-p/247627#M56327</link>
      <description>&lt;DIV align="center"&gt;&lt;P&gt;Here is the table. It is in the character format and with regards to separating everything before 2010 and after 2011 it is okay. The data only contains 2010 and 2011&lt;/P&gt;Alphabetic List of Variables and Attributes # Variable Type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&gt;$3.&lt;/TD&gt;&lt;TD&gt;Postal_Code&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Region&lt;/TD&gt;&lt;TD&gt;Char&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;$10.&lt;/TD&gt;&lt;TD&gt;$10.&lt;/TD&gt;&lt;TD&gt;Region&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Specialty&lt;/TD&gt;&lt;TD&gt;Num&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;BEST.&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Specialty&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 02 Feb 2016 22:19:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-split-observations-by-date/m-p/247627#M56327</guid>
      <dc:creator>jwill731</dc:creator>
      <dc:date>2016-02-02T22:19:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do I split observations by date?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-split-observations-by-date/m-p/247629#M56328</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data pei2010 pei2011;
set have;
wantvar=input(strip(Date_of_Service),mmddyy8.);
if wantvar &amp;gt; '31Dec2010'd then output pei2011;
if wantvar &amp;lt;= '31Dec2010'd then output pei2010;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This should work. The rest i think you know what you are doing.&lt;/P&gt;
&lt;P&gt;Note: mmddyy8. or&amp;nbsp;&lt;SPAN&gt;mmddyy10. &amp;nbsp;, depend on you date if the year is in two digit or four digit.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2016 22:32:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-split-observations-by-date/m-p/247629#M56328</guid>
      <dc:creator>mohamed_zaki</dc:creator>
      <dc:date>2016-02-02T22:32:11Z</dc:date>
    </item>
    <item>
      <title>Re: How do I split observations by date?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-split-observations-by-date/m-p/247633#M56329</link>
      <description>&lt;P&gt;Okay thanks a lot! I will try this out&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2016 23:10:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-split-observations-by-date/m-p/247633#M56329</guid>
      <dc:creator>jwill731</dc:creator>
      <dc:date>2016-02-02T23:10:31Z</dc:date>
    </item>
    <item>
      <title>Re: How do I split observations by date?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-split-observations-by-date/m-p/247673#M56330</link>
      <description>The data can be separated without INPUT() conversion.&lt;BR /&gt;For example&lt;BR /&gt;If scan( date_of_service, -1 , '/' ) = '2010' then output pei2010 ; else output pei2011 ;&lt;BR /&gt;However having the value stored in standard SAS date form will support downstream reporting far better than that string. Unfortunately your source system might choose string storage because some values might not convert well ....&lt;BR /&gt;dates before 1582 (a very old church)&lt;BR /&gt;or containing strings without year (elderly might remember only when the anniversary falls unsure of that year of birth)&lt;BR /&gt;or just uncleansed data&lt;BR /&gt;</description>
      <pubDate>Wed, 03 Feb 2016 08:58:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-split-observations-by-date/m-p/247673#M56330</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2016-02-03T08:58:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do I split observations by date?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-split-observations-by-date/m-p/247796#M56339</link>
      <description>&lt;P&gt;One very powerful feature of SAS that you may not be aware of is BY group processing. If you are separating the data and intend to do the same steps to each set then the separation may not be needed. Add a YEAR variable to the data and then most procedures allow use of BY Year; to create the output for each level of the Year variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And for many actions if the date is a SAS date value (as the WANTVAR create by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/49185"&gt;@mohamed_zaki﻿&lt;/a&gt;)&amp;nbsp;you can use a format to create groups 'on the fly' for processing. A brief example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
   set have;
   wantvar=input(strip(Date_of_Service),mmddyy8.);
run;

proc means data= example max min std sum;
   class wantvar;
   format wantvar year4.;
   var Paid_amt;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;creates a summary for each year in the data.&lt;/P&gt;
&lt;P&gt;A change in format such as to YYMM or YYMON&amp;nbsp;would create a monthy summary with year information, or YYQ to get get calendar quarters.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2016 16:50:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-split-observations-by-date/m-p/247796#M56339</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-02-03T16:50:23Z</dc:date>
    </item>
  </channel>
</rss>

