<?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 creating subset of data by year in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/creating-subset-of-data-by-year/m-p/552463#M153576</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
  input patientid  start1_date : mmddyy10. ;
  format  start1_date  mmddyy10.;
datalines;
1 5/5/2009 
2 6/6/2010
3 7/7/2011
4 5/5/2011 
5 6/6/2012 



;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have the above data, I am trying to create a subset for each year individually:&lt;/P&gt;&lt;P&gt;Output&lt;/P&gt;&lt;P&gt;data09 would include&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;1 5/5/2009 &lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;data10 include&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;2 6/6/2010 &lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;data11 include&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;3 7/7/2011&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;4 5/5/2011&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;and so on&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 19 Apr 2019 15:04:30 GMT</pubDate>
    <dc:creator>lillymaginta</dc:creator>
    <dc:date>2019-04-19T15:04:30Z</dc:date>
    <item>
      <title>creating subset of data by year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-subset-of-data-by-year/m-p/552463#M153576</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
  input patientid  start1_date : mmddyy10. ;
  format  start1_date  mmddyy10.;
datalines;
1 5/5/2009 
2 6/6/2010
3 7/7/2011
4 5/5/2011 
5 6/6/2012 



;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have the above data, I am trying to create a subset for each year individually:&lt;/P&gt;&lt;P&gt;Output&lt;/P&gt;&lt;P&gt;data09 would include&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;1 5/5/2009 &lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;data10 include&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;2 6/6/2010 &lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;data11 include&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;3 7/7/2011&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;4 5/5/2011&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;and so on&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Apr 2019 15:04:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-subset-of-data-by-year/m-p/552463#M153576</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2019-04-19T15:04:30Z</dc:date>
    </item>
    <item>
      <title>Re: creating subset of data by year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-subset-of-data-by-year/m-p/552465#M153578</link>
      <description>&lt;P&gt;This type of splitting of data is generally not recommended, and you would be (in almost all cases that I know of) keeping the data in one single dataset. it is more work (programming a loop to handle each year) and little benefit. If the data is all together, you can analyze the data by year by using the BY statement in almost any PROC.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Apr 2019 15:14:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-subset-of-data-by-year/m-p/552465#M153578</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-04-19T15:14:25Z</dc:date>
    </item>
    <item>
      <title>Re: creating subset of data by year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-subset-of-data-by-year/m-p/552470#M153581</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/72105"&gt;@lillymaginta&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; 's recommendation is absolute and true. However, for what it's worth&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data a;
  input patientid  start1_date : mmddyy10. ;
  format  start1_date  mmddyy10.;
datalines;
1 5/5/2009 
2 6/6/2010
3 7/7/2011
4 5/5/2011 
5 6/6/2012 
;

data  temp;
set a;
year=year(start1_date);
run;

proc sql ;                                                              
  create index year on temp (year) ;                      
quit ;                                                                  
                                                                        
data _null_ ;                                                           
  if _n_ = 1 then do ;                                                  
    dcl hash h () ;                                                     
    h.definekey  ("_n_") ;                                              
    h.definedata ('patientid','start1_date','year') ;
    h.definedone () ;                                                   
  end ;                                                                 
  do _n_ = 1 by 1 until (last.year) ;                            
    set temp ;                                                          
    by year ;                                                    
    h.add() ;                                                           
  end ;                                                                 
  h.output (dataset: catx ("_", "year",year)) ;          
  h.clear() ;                                                           
run ;             &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Apr 2019 15:43:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-subset-of-data-by-year/m-p/552470#M153581</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-19T15:43:10Z</dc:date>
    </item>
  </channel>
</rss>

