<?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: pick observation from subgroups in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/pick-observation-from-subgroups/m-p/13346#M1932</link>
    <description>Hi data_null,&lt;BR /&gt;
&lt;BR /&gt;
I run the codes and they work exactly in the way I want!&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
    <pubDate>Sat, 19 Feb 2011 19:25:00 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2011-02-19T19:25:00Z</dc:date>
    <item>
      <title>pick observation from subgroups</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/pick-observation-from-subgroups/m-p/13343#M1929</link>
      <description>Hi everyone, &lt;BR /&gt;
&lt;BR /&gt;
I have data set from which I need to add the 1st, 2nd, 3rd, 4th, ..., nth value up in each subgroup.&lt;BR /&gt;
&lt;BR /&gt;
For example, the data set looks like,&lt;BR /&gt;
&lt;BR /&gt;
Name          Year_count  Starting_Year&lt;BR /&gt;
A                   7                  1995&lt;BR /&gt;
A                   4                   2000&lt;BR /&gt;
B                   2                  1997&lt;BR /&gt;
B                  4                   2000&lt;BR /&gt;
C                  3                   2003&lt;BR /&gt;
C                  1                   2006&lt;BR /&gt;
C                  2                   2007&lt;BR /&gt;
..................................................&lt;BR /&gt;
X                  5                  1992&lt;BR /&gt;
X                  3                  1997&lt;BR /&gt;
X                  1                   2000&lt;BR /&gt;
&lt;BR /&gt;
I want to put the first observation in A, B, C, ...., and X  in a new group, the 2nd observation in A, B, C,... and X in a new group, and so on. The number of observation in each subgroup by name may vary, 2 for A, 2 for B, 3 for C,..., 3 for X.&lt;BR /&gt;
&lt;BR /&gt;
the outcome will look like,&lt;BR /&gt;
Name          Year_count  Starting_Year&lt;BR /&gt;
A                   7                  1995&lt;BR /&gt;
B                   2                  1997&lt;BR /&gt;
C                  3                   2003&lt;BR /&gt;
...............................................&lt;BR /&gt;
X                  5                  1992&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Please help me, thanks!</description>
      <pubDate>Fri, 18 Feb 2011 21:10:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/pick-observation-from-subgroups/m-p/13343#M1929</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-02-18T21:10:35Z</dc:date>
    </item>
    <item>
      <title>Re: pick observation from subgroups</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/pick-observation-from-subgroups/m-p/13344#M1930</link>
      <description>Hi jie.su2134  &lt;BR /&gt;
pls. see following code. groupcount variable count number of group. A=1, B=2 ...&lt;BR /&gt;
count variable calculate number in the each group. &lt;BR /&gt;
&lt;BR /&gt;
 proc sort data=x out x ; by name ; run ;&lt;BR /&gt;
&lt;BR /&gt;
 data x;&lt;BR /&gt;
 set x ;&lt;BR /&gt;
  by name ;&lt;BR /&gt;
&lt;BR /&gt;
 groupcount +1 ;&lt;BR /&gt;
 if first.name then count=1 ;&lt;BR /&gt;
  count+1; &lt;BR /&gt;
 &lt;BR /&gt;
  if groupcount = count then output ;&lt;BR /&gt;
run ; &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Irena</description>
      <pubDate>Fri, 18 Feb 2011 22:00:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/pick-observation-from-subgroups/m-p/13344#M1930</guid>
      <dc:creator>ariari</dc:creator>
      <dc:date>2011-02-18T22:00:43Z</dc:date>
    </item>
    <item>
      <title>Re: pick observation from subgroups</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/pick-observation-from-subgroups/m-p/13345#M1931</link>
      <description>I don't know if I understand the question so this may be totally goofy.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data ungrouped;&lt;BR /&gt;
   input Name:$1. Year_count Starting_Year;&lt;BR /&gt;
   cards;&lt;BR /&gt;
A 7 1995&lt;BR /&gt;
A 4 2000&lt;BR /&gt;
B 2 1997&lt;BR /&gt;
B 4 2000&lt;BR /&gt;
C 3 2003&lt;BR /&gt;
C 1 2006&lt;BR /&gt;
C 2 2007&lt;BR /&gt;
X 5 1992&lt;BR /&gt;
X 3 1997&lt;BR /&gt;
X 1 2000&lt;BR /&gt;
;;;;&lt;BR /&gt;
   run;&lt;BR /&gt;
data groupedV / view=groupedV;&lt;BR /&gt;
   do group=1 by 1 until(last.name);&lt;BR /&gt;
      set ungrouped;&lt;BR /&gt;
      by name;&lt;BR /&gt;
      output;&lt;BR /&gt;
      end;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc sort data=groupedV out=grouped;&lt;BR /&gt;
   by group;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
&lt;BR /&gt;
                        Year_    Starting_&lt;BR /&gt;
Obs    group    Name    count       Year&lt;BR /&gt;
&lt;BR /&gt;
  1      1       A        7         1995&lt;BR /&gt;
  2      1       B        2         1997&lt;BR /&gt;
  3      1       C        3         2003&lt;BR /&gt;
  4      1       X        5         1992&lt;BR /&gt;
  5      2       A        4         2000&lt;BR /&gt;
  6      2       B        4         2000&lt;BR /&gt;
  7      2       C        1         2006&lt;BR /&gt;
  8      2       X        3         1997&lt;BR /&gt;
  9      3       C        2         2007&lt;BR /&gt;
 10      3       X        1         2000&lt;BR /&gt;
[/pre]</description>
      <pubDate>Fri, 18 Feb 2011 23:10:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/pick-observation-from-subgroups/m-p/13345#M1931</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2011-02-18T23:10:59Z</dc:date>
    </item>
    <item>
      <title>Re: pick observation from subgroups</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/pick-observation-from-subgroups/m-p/13346#M1932</link>
      <description>Hi data_null,&lt;BR /&gt;
&lt;BR /&gt;
I run the codes and they work exactly in the way I want!&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
      <pubDate>Sat, 19 Feb 2011 19:25:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/pick-observation-from-subgroups/m-p/13346#M1932</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-02-19T19:25:00Z</dc:date>
    </item>
    <item>
      <title>Re: pick observation from subgroups</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/pick-observation-from-subgroups/m-p/13347#M1933</link>
      <description>Hi.&lt;BR /&gt;
if  you like Hash Table which has high efficient.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data ungrouped;&lt;BR /&gt;
   input Name:$1. Year_count Starting_Year;&lt;BR /&gt;
   cards;&lt;BR /&gt;
A 7 1995&lt;BR /&gt;
A 4 2000&lt;BR /&gt;
B 2 1997&lt;BR /&gt;
B 4 2000&lt;BR /&gt;
C 3 2003&lt;BR /&gt;
C 1 2006&lt;BR /&gt;
C 2 2007&lt;BR /&gt;
X 5 1992&lt;BR /&gt;
X 3 1997&lt;BR /&gt;
X 1 2000&lt;BR /&gt;
;;;;&lt;BR /&gt;
   run;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
 declare hash group(ordered: 'a');&lt;BR /&gt;
 group.definekey('count','name');&lt;BR /&gt;
 group.definedata('name','year_count','starting_year');&lt;BR /&gt;
 group.definedone();&lt;BR /&gt;
&lt;BR /&gt;
 do until(last);&lt;BR /&gt;
  set ungrouped end=last;&lt;BR /&gt;
  if name ne lag(name) then count=0;&lt;BR /&gt;
  count+1;&lt;BR /&gt;
  group.add();&lt;BR /&gt;
 end;&lt;BR /&gt;
 group.output(dataset: 'grouped');&lt;BR /&gt;
 stop;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Mon, 21 Feb 2011 02:26:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/pick-observation-from-subgroups/m-p/13347#M1933</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-02-21T02:26:27Z</dc:date>
    </item>
  </channel>
</rss>

