<?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 How to pick out the nonmissing first 2 observation per proc sort by variables:  id , ord and test in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-pick-out-the-nonmissing-first-2-observation-per-proc-sort/m-p/780749#M248788</link>
    <description>&lt;P&gt;hi all:&lt;/P&gt;&lt;P&gt;I tried to use data step or proc sql to find out the /*result*/ any suggestions? thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input id ord test $4.;&lt;BR /&gt;datalines;&lt;BR /&gt;1 0 A&lt;/P&gt;&lt;P&gt;1 0 B&lt;BR /&gt;1 1 A&lt;BR /&gt;1 1 A&lt;BR /&gt;1 1 B&lt;BR /&gt;1 3 A&lt;BR /&gt;1 3 B&lt;BR /&gt;2 0&lt;BR /&gt;3 0.2 A&lt;BR /&gt;3 0.2 B&lt;BR /&gt;3 1 A&lt;BR /&gt;3 1 B&lt;BR /&gt;3 2 A&lt;BR /&gt;3 2 B&lt;BR /&gt;3 3 A&lt;BR /&gt;3 3 B&lt;BR /&gt;3 4 A&lt;BR /&gt;4 1 A&lt;BR /&gt;4 1 B&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;/*&lt;/P&gt;&lt;P&gt;desired output look like this:&lt;/P&gt;&lt;P&gt;1 0 A&lt;BR /&gt;1 0 B&lt;/P&gt;&lt;P&gt;3 0.2 A&lt;BR /&gt;3 0.2 B&lt;BR /&gt;4 1 A&lt;BR /&gt;4 1 B&lt;/P&gt;&lt;P&gt;*/&lt;/P&gt;</description>
    <pubDate>Wed, 17 Nov 2021 14:29:07 GMT</pubDate>
    <dc:creator>purpleclothlady</dc:creator>
    <dc:date>2021-11-17T14:29:07Z</dc:date>
    <item>
      <title>How to pick out the nonmissing first 2 observation per proc sort by variables:  id , ord and test</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pick-out-the-nonmissing-first-2-observation-per-proc-sort/m-p/780749#M248788</link>
      <description>&lt;P&gt;hi all:&lt;/P&gt;&lt;P&gt;I tried to use data step or proc sql to find out the /*result*/ any suggestions? thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input id ord test $4.;&lt;BR /&gt;datalines;&lt;BR /&gt;1 0 A&lt;/P&gt;&lt;P&gt;1 0 B&lt;BR /&gt;1 1 A&lt;BR /&gt;1 1 A&lt;BR /&gt;1 1 B&lt;BR /&gt;1 3 A&lt;BR /&gt;1 3 B&lt;BR /&gt;2 0&lt;BR /&gt;3 0.2 A&lt;BR /&gt;3 0.2 B&lt;BR /&gt;3 1 A&lt;BR /&gt;3 1 B&lt;BR /&gt;3 2 A&lt;BR /&gt;3 2 B&lt;BR /&gt;3 3 A&lt;BR /&gt;3 3 B&lt;BR /&gt;3 4 A&lt;BR /&gt;4 1 A&lt;BR /&gt;4 1 B&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;/*&lt;/P&gt;&lt;P&gt;desired output look like this:&lt;/P&gt;&lt;P&gt;1 0 A&lt;BR /&gt;1 0 B&lt;/P&gt;&lt;P&gt;3 0.2 A&lt;BR /&gt;3 0.2 B&lt;BR /&gt;4 1 A&lt;BR /&gt;4 1 B&lt;/P&gt;&lt;P&gt;*/&lt;/P&gt;</description>
      <pubDate>Wed, 17 Nov 2021 14:29:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pick-out-the-nonmissing-first-2-observation-per-proc-sort/m-p/780749#M248788</guid>
      <dc:creator>purpleclothlady</dc:creator>
      <dc:date>2021-11-17T14:29:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to pick out the nonmissing first 2 observation per proc sort by variables:  id , ord and tes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pick-out-the-nonmissing-first-2-observation-per-proc-sort/m-p/780763#M248798</link>
      <description>&lt;P&gt;This works for your example data:&lt;/P&gt;
&lt;PRE&gt;data test;
infile datalines missover;
input id ord test $4.;
datalines;
1 0 A
1 0 B
1 1 A
1 1 A
1 1 B
1 3 A
1 3 B
2 0
3 0.2 A
3 0.2 B
3 1 A
3 1 B
3 2 A
3 2 B
3 3 A
3 3 B
3 4 A
4 1 A
4 1 B
run;

data want;
  set test;
  by id ord;
  retain counter;
  if first.id then counter=1;
  else counter+1;
  if first.ord = last.ord then delete;
  else if counter le 2;
  drop counter;
run;&lt;/PRE&gt;
&lt;P&gt;Note that I tweaked your data step code because the missing value for Test causes issues. Suggest posting code in a text box or code box.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/347922"&gt;@purpleclothlady&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;hi all:&lt;/P&gt;
&lt;P&gt;I tried to use data step or proc sql to find out the /*result*/ any suggestions? thanks in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data test;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input id ord test $4.;&lt;BR /&gt;datalines;&lt;BR /&gt;1 0 A&lt;/P&gt;
&lt;P&gt;1 0 B&lt;BR /&gt;1 1 A&lt;BR /&gt;1 1 A&lt;BR /&gt;1 1 B&lt;BR /&gt;1 3 A&lt;BR /&gt;1 3 B&lt;BR /&gt;2 0&lt;BR /&gt;3 0.2 A&lt;BR /&gt;3 0.2 B&lt;BR /&gt;3 1 A&lt;BR /&gt;3 1 B&lt;BR /&gt;3 2 A&lt;BR /&gt;3 2 B&lt;BR /&gt;3 3 A&lt;BR /&gt;3 3 B&lt;BR /&gt;3 4 A&lt;BR /&gt;4 1 A&lt;BR /&gt;4 1 B&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;/*&lt;/P&gt;
&lt;P&gt;desired output look like this:&lt;/P&gt;
&lt;P&gt;1 0 A&lt;BR /&gt;1 0 B&lt;/P&gt;
&lt;P&gt;3 0.2 A&lt;BR /&gt;3 0.2 B&lt;BR /&gt;4 1 A&lt;BR /&gt;4 1 B&lt;/P&gt;
&lt;P&gt;*/&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Nov 2021 15:40:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pick-out-the-nonmissing-first-2-observation-per-proc-sort/m-p/780763#M248798</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-11-17T15:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to pick out the nonmissing first 2 observation per proc sort by variables:  id , ord and tes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pick-out-the-nonmissing-first-2-observation-per-proc-sort/m-p/780765#M248800</link>
      <description>&lt;P&gt;You just need to count the observations within an id.&lt;/P&gt;
&lt;P&gt;For example you could nest the SET statement inside a DO loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do obs=1 by 1 until(last.id);
    set test;
    by id;
    if obs&amp;lt;=2 and not (first.id and last.id) then output;
  end;
  drop obs;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Nov 2021 16:01:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pick-out-the-nonmissing-first-2-observation-per-proc-sort/m-p/780765#M248800</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-17T16:01:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to pick out the nonmissing first 2 observation per proc sort by variables:  id , ord and tes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pick-out-the-nonmissing-first-2-observation-per-proc-sort/m-p/780766#M248801</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;Note that I tweaked your data step code because the missing value for Test causes issues. Suggest posting code in a text box or code box.&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not sure that you mean.&amp;nbsp; It looks like you added the MISSOVER option to the INFILE statement.&amp;nbsp; That was not needed with in-line data as card images are always fix length (a multiple of 80 bytes).&lt;/P&gt;
&lt;P&gt;But even if you did have the data in an external file:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options parmcards=example;
filename example temp;
parmcards;
1 0 A
1 0 B
1 1 A
1 1 A
1 1 B
1 3 A
1 3 B
2 0
3 0.2 A
3 0.2 B
3 1 A
3 1 B
3 2 A
3 2 B
3 3 A
3 3 B
3 4 A
4 1 A
4 1 B
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You wouldn't want to use the MISSOVER option with the formatted input statement, you would need the TRUNCOVER option.&lt;/P&gt;
&lt;P&gt;Check out what happens:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
  infile example missover;
  input id ord test $4.;
run;

data test3;
  infile example truncover;
  input id ord test $4.;
run;

proc compare data=test2 compare=test3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can make the MISSOVER option work if you make sure to always use LIST MODE input statements.&amp;nbsp; For example by prefixing any in-line informat specification with the colon modifier.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  input id ord test :$4.;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Nov 2021 16:07:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pick-out-the-nonmissing-first-2-observation-per-proc-sort/m-p/780766#M248801</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-17T16:07:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to pick out the nonmissing first 2 observation per proc sort by variables:  id , ord and tes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pick-out-the-nonmissing-first-2-observation-per-proc-sort/m-p/781104#M248938</link>
      <description>Hi Tom:&lt;BR /&gt;that works .thanks a ton</description>
      <pubDate>Thu, 18 Nov 2021 19:01:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pick-out-the-nonmissing-first-2-observation-per-proc-sort/m-p/781104#M248938</guid>
      <dc:creator>purpleclothlady</dc:creator>
      <dc:date>2021-11-18T19:01:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to pick out the nonmissing first 2 observation per proc sort by variables:  id , ord and tes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pick-out-the-nonmissing-first-2-observation-per-proc-sort/m-p/781106#M248940</link>
      <description>hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;:&lt;BR /&gt;thanks for the reminder. I appreciate that</description>
      <pubDate>Thu, 18 Nov 2021 19:02:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pick-out-the-nonmissing-first-2-observation-per-proc-sort/m-p/781106#M248940</guid>
      <dc:creator>purpleclothlady</dc:creator>
      <dc:date>2021-11-18T19:02:10Z</dc:date>
    </item>
  </channel>
</rss>

