<?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: sampling by Category in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sampling-by-Category/m-p/246458#M46113</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;yeah ,&amp;nbsp;I do have a date value associated with each account but it is not sas date value. here I have included a sample of one account:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/12242i043E4FEC946DBD40/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="account_data.JPG" title="account_data.JPG" /&gt;</description>
    <pubDate>Wed, 27 Jan 2016 20:45:18 GMT</pubDate>
    <dc:creator>nismail1976</dc:creator>
    <dc:date>2016-01-27T20:45:18Z</dc:date>
    <item>
      <title>sampling by Category</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sampling-by-Category/m-p/246444#M46107</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;I have &amp;nbsp;100 accounts and for each account I have&amp;nbsp;3 years&amp;nbsp;worth of monthly&amp;nbsp;observations. Now this is what I am trying to do:&lt;/P&gt;
&lt;P&gt;I need to get one&amp;nbsp;&amp;nbsp;random observation from each account in the second year. can someone share some code or thoughts please?&lt;/P&gt;
&lt;P&gt;(I have no idea how to do this)&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;bill&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2016 20:10:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sampling-by-Category/m-p/246444#M46107</guid>
      <dc:creator>nismail1976</dc:creator>
      <dc:date>2016-01-27T20:10:21Z</dc:date>
    </item>
    <item>
      <title>Re: sampling by Category</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sampling-by-Category/m-p/246450#M46111</link>
      <description>&lt;P&gt;It would help to have some data so we can see what you have. Do you have a date associated with each record? Is it a SAS date value?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The generic approach would be:&lt;/P&gt;
&lt;P&gt;Identify the years associated with each account (which is very easy if there are SAS date values with each record)&lt;/P&gt;
&lt;P&gt;Use that info to find the "second year".&lt;/P&gt;
&lt;P&gt;Use that to select the appropriate records&lt;/P&gt;
&lt;P&gt;Then Proc surveyselect with account as a strata variable and a sample size of 1 for each strata.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2016 20:29:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sampling-by-Category/m-p/246450#M46111</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-01-27T20:29:18Z</dc:date>
    </item>
    <item>
      <title>Re: sampling by Category</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sampling-by-Category/m-p/246458#M46113</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;yeah ,&amp;nbsp;I do have a date value associated with each account but it is not sas date value. here I have included a sample of one account:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/12242i043E4FEC946DBD40/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="account_data.JPG" title="account_data.JPG" /&gt;</description>
      <pubDate>Wed, 27 Jan 2016 20:45:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sampling-by-Category/m-p/246458#M46113</guid>
      <dc:creator>nismail1976</dc:creator>
      <dc:date>2016-01-27T20:45:18Z</dc:date>
    </item>
    <item>
      <title>Re: sampling by Category</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sampling-by-Category/m-p/246474#M46120</link>
      <description>&lt;P&gt;Here's an example that starts from reading a data set.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
   informat account $6. date mmddyy10.;
   format date mmddyy10.;
   input account $ date balance;
datalines;
123456   01/01/2010     7503.96                                                                   
123456   02/01/2010     3209.12                                                                   
123456   03/01/2010     1783.9                                                                    
123456   04/01/2010     9060.33                                                                   
123456   05/01/2010     3571.17                                                                   
123456   06/01/2010     2211.14                                                                   
123456   07/01/2010     7864.38                                                                   
123456   08/01/2010     3980.82                                                                   
123456   09/01/2010     1246.65                                                                   
123456   10/01/2010     1876.86                                                                   
123456   11/01/2010     7761.84                                                                   
123456   12/01/2010     4360.74                                                                   
123456   01/01/2011     9675                                                                      
123456   02/01/2011     2637.03                                                                   
123456   03/01/2011     7139.34                                                                   
123456   04/01/2011     5548.58                                                                   
123456   05/01/2011     5312.5                                                                    
123456   06/01/2011     8613.45                                                                   
123456   07/01/2011     1420.78                                                                   
123456   08/01/2011     8604.25                                                                   
123456   09/01/2011     6530.96                                                                   
123456   10/01/2011     7699.56                                                                   
123456   11/01/2011     7021.56                                                                   
123456   12/01/2011     3287.5                                                                    
123456   01/01/2012     5220.85                                                                   
123456   02/01/2012     9333.98                                                                   
123456   03/01/2012     464.67                                                                    
123456   04/01/2012     6148.54                                                                   
123456   05/01/2012     6575.28                                                                   
123456   06/01/2012     3726.44                                                                   
123456   07/01/2012     5884.72                                                                   
123456   08/01/2012     3122.34                                                                   
123456   09/01/2012     5392.72                                                                   
123456   10/01/2012     2817.66                                                                   
123456   11/01/2012     5282.22                                                                   
123456   12/01/2012     5584.1                                                                    
abcdef   01/01/2011     982.19                                                                    
abcdef   02/01/2011     1087.89                                                                   
abcdef   03/01/2011     5816.67                                                                   
abcdef   04/01/2011     6748.67                                                                   
abcdef   05/01/2011     4827.11                                                                   
abcdef   06/01/2011     1459.01                                                                   
abcdef   07/01/2011     7511.13                                                                   
abcdef   08/01/2011     9609.37                                                                   
abcdef   09/01/2011     7579.12                                                                   
abcdef   10/01/2011     9603.67                                                                   
abcdef   11/01/2011     941.16                                                                    
abcdef   12/01/2011     6773.56                                                                   
abcdef   01/01/2012     8921                                                                      
abcdef   02/01/2012     2841.61                                                                   
abcdef   03/01/2012     6610.11                                                                   
abcdef   04/01/2012     7994.27                                                                   
abcdef   05/01/2012     7926.96                                                                   
abcdef   06/01/2012     3194.98                                                                   
abcdef   07/01/2012     7788.71                                                                   
abcdef   08/01/2012     5450.36                                                                   
abcdef   09/01/2012     7049.72                                                                   
abcdef   10/01/2012     8322.97                                                                   
abcdef   11/01/2012     969.01                                                                    
abcdef   12/01/2012     721.47                                                                    
abcdef   01/01/2013     2530.07                                                                   
abcdef   02/01/2013     2339.33                                                                   
abcdef   03/01/2013     7936.15                                                                   
abcdef   04/01/2013     6852.09                                                                   
abcdef   05/01/2013     2589.46                                                                   
abcdef   06/01/2013     8571.48                                                                   
abcdef   07/01/2013     4732.78                                                                   
abcdef   08/01/2013     6865.38                                                                   
abcdef   09/01/2013     7025.47                                                                   
abcdef   10/01/2013     5461.62                                                                   
abcdef   11/01/2013     754.21                                                                    
abcdef   12/01/2013     6273.52                                                                   
;
run;

/* one of many ways to get one record per account per year*/
proc summary data=have nway;
   class account date;
   format date year4.;
   var balance;
   output out=HaveCount n=;
run;
/* get a value for second year for each account*/
data SecondYear;
   set HaveCount;
   by account;
   retain SecondYearFlag 0;
   if first.account then SecondYearFlag=1;
   else SecondYearFlag+1;
   Year = year(date);
   if SecondYearFlag=2;
   keep account year;
run;
/* get all of the data back for just the second year*/

proc sql;
   create table SecondYearData as
   select have.*
   from secondyear left join have on 
        secondyear.account=have.account and secondyear.year= year(have.date)
   order by have.account, have.date
   ;
quit;

proc surveyselect data=secondyeardata out=want 
     sampsize=1;
     strata account;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Jan 2016 21:14:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sampling-by-Category/m-p/246474#M46120</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-01-27T21:14:50Z</dc:date>
    </item>
    <item>
      <title>Re: sampling by Category</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sampling-by-Category/m-p/246478#M46122</link>
      <description>&lt;P&gt;Thank you so much, you are amazing!&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2016 21:37:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sampling-by-Category/m-p/246478#M46122</guid>
      <dc:creator>nismail1976</dc:creator>
      <dc:date>2016-01-27T21:37:35Z</dc:date>
    </item>
    <item>
      <title>Re: sampling by Category</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sampling-by-Category/m-p/246481#M46123</link>
      <description>&lt;P&gt;I really appreciate it!&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2016 21:42:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sampling-by-Category/m-p/246481#M46123</guid>
      <dc:creator>nismail1976</dc:creator>
      <dc:date>2016-01-27T21:42:22Z</dc:date>
    </item>
  </channel>
</rss>

