<?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: keep first N observations for each factor-level combination in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/keep-first-N-observations-for-each-factor-level-combination/m-p/552808#M153704</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your reply.&amp;nbsp; And sorry for not explaining it more clearly. I want to make it so each i-j combination has the same number of observations. If I do ID&amp;gt;200 or MYDATA(obs=200), it looks like it will just pull whatever the first 200 observations are. I want each combination to have 20 observations.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="proc freq.png" style="width: 286px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28857i9D6397E4D4C33FBE/image-size/large?v=v2&amp;amp;px=999" role="button" title="proc freq.png" alt="proc freq.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 22 Apr 2019 12:30:21 GMT</pubDate>
    <dc:creator>blmreil</dc:creator>
    <dc:date>2019-04-22T12:30:21Z</dc:date>
    <item>
      <title>keep first N observations for each factor-level combination</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-first-N-observations-for-each-factor-level-combination/m-p/552756#M153687</link>
      <description>&lt;P&gt;Hi. I'm new to SAS so I'd greatly appreciate any help anyone could provide me. So say, I have a data set with ~500 observations and my ultimate goal is to run ANCOVA of this data set with response variable y, factors i and j, and possible covariates k and l. I have 5 levels of i and two levels of j. Since, I first want to try to run a completely balanced ANCOVA, I don't want to use the entire data set, just the first n observations (according to ID) for each of the ten factor-level combinations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I initially wrote a line with&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;IF (ID &amp;gt; 10*n) then delete;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;before realizing how stupid that is.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How would I go about doing this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's a mockup of what part of the data looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp;i&amp;nbsp; &amp;nbsp; j&amp;nbsp; &amp;nbsp;k&amp;nbsp; &amp;nbsp;l&amp;nbsp; &amp;nbsp;y&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp;1&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp;1&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp;1&lt;BR /&gt;4&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp;1&lt;BR /&gt;5&amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp;2&lt;BR /&gt;6&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp;1&lt;BR /&gt;7&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp;2&lt;BR /&gt;8&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp;2&lt;BR /&gt;9&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp;1&lt;BR /&gt;10&amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp;2&lt;BR /&gt;11&amp;nbsp; 1&amp;nbsp; &amp;nbsp;1&lt;BR /&gt;12&amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp;2&lt;BR /&gt;13&amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp;1&lt;BR /&gt;14&amp;nbsp; &amp;nbsp;1&amp;nbsp; 2&lt;BR /&gt;15&amp;nbsp; &amp;nbsp;5&amp;nbsp; 1&lt;BR /&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So i=1, j=1, would have ID 11 as the first observation.&lt;BR /&gt;and i=2, j=1, would have ID 3, ID 13, etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It feels like this should be a pretty simple thing to do but I cannot for the life of me figure out how to do it. Would anybody be able to point me in the right direction?&amp;nbsp;Thanks in advance for your help!&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 05:51:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-first-N-observations-for-each-factor-level-combination/m-p/552756#M153687</guid>
      <dc:creator>blmreil</dc:creator>
      <dc:date>2019-04-22T05:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: keep first N observations for each factor-level combination</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-first-N-observations-for-each-factor-level-combination/m-p/552773#M153698</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;There are many ways to get the first N obsevations.&lt;/P&gt;
&lt;P&gt;Use the statement as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;IF&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;ID&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;gt;&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;n&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;delete&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;If your data set is named as MYDATA, then use;&lt;/P&gt;
&lt;P&gt;set MYDATA(obs=n);&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 08:52:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-first-N-observations-for-each-factor-level-combination/m-p/552773#M153698</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2019-04-22T08:52:56Z</dc:date>
    </item>
    <item>
      <title>Re: keep first N observations for each factor-level combination</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-first-N-observations-for-each-factor-level-combination/m-p/552808#M153704</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your reply.&amp;nbsp; And sorry for not explaining it more clearly. I want to make it so each i-j combination has the same number of observations. If I do ID&amp;gt;200 or MYDATA(obs=200), it looks like it will just pull whatever the first 200 observations are. I want each combination to have 20 observations.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="proc freq.png" style="width: 286px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28857i9D6397E4D4C33FBE/image-size/large?v=v2&amp;amp;px=999" role="button" title="proc freq.png" alt="proc freq.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 12:30:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-first-N-observations-for-each-factor-level-combination/m-p/552808#M153704</guid>
      <dc:creator>blmreil</dc:creator>
      <dc:date>2019-04-22T12:30:21Z</dc:date>
    </item>
    <item>
      <title>Re: keep first N observations for each factor-level combination</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-first-N-observations-for-each-factor-level-combination/m-p/552838#M153717</link>
      <description>&lt;P&gt;Yes. Now I see your requirement. It takes more time to give you solution without knowing some sample data set. Again you may want random sample in each i-j th combination. I have very limited time to give you a solution immediately. Someone will help you soon.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 14:03:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-first-N-observations-for-each-factor-level-combination/m-p/552838#M153717</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2019-04-22T14:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: keep first N observations for each factor-level combination</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-first-N-observations-for-each-factor-level-combination/m-p/552891#M153723</link>
      <description>&lt;P&gt;Refer to the following and see Example 4:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stats.idre.ucla.edu/sas/faq/how-can-i-take-a-stratified-random-sample-of-my-data/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/faq/how-can-i-take-a-stratified-random-sample-of-my-data/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 15:06:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-first-N-observations-for-each-factor-level-combination/m-p/552891#M153723</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2019-04-22T15:06:51Z</dc:date>
    </item>
  </channel>
</rss>

