<?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 collect obs from several dataset into individual datasets? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-collect-obs-from-several-dataset-into-individual-datasets/m-p/447278#M112309</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have dataset several like this.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have2000 ;
input
ID$4. SALE YEAR;
datalines;
6734 28 2000
1234 23 2000
0034 32 2000
2234 44 2000
;
run;

data have2001 ;
input
ID$4. SALE YEAR;
datalines;
6734 17 2001
1234 52 2001
0034 75 2001
2234 44 2001
1234 26 2001
;
run;

data have2002 ;
input
ID$4. SALE YEAR;
datalines;
6734 11 2002
1234 23 2002
0034 33 2002
2234 15 2002
1234 13 2002
8334 44 2002
;
run;

data have2003 ;
input
ID$4. SALE YEAR;
datalines;
6734 56 2003
1234 43 2003
0034 35 2003
2234 44 2003
1234 45 2003
8334 23 2003
2234 22 2003
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is what I would like to acheive.&lt;/P&gt;&lt;P&gt;Collect all the observation with the same &lt;STRONG&gt;ID&lt;/STRONG&gt; over all dataset I have, and put those observation together in a new dataset and name the new dataset by its &lt;STRONG&gt;ID. Their variable name is basically the same.&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want_id_6734;
input
ID$4. SALE YEAR;
datalines;
6734 56 2003
6734 11 2002
6734 17 2001
6734 28 2000
;
run;

data want_id_1234;
input
ID$4. SALE YEAR;
datalines;
1234 43 2003
1234 45 2003
1234 23 2002
1234 13 2002
1234 52 2001
1234 26 2001
1234 23 2000
;
run;

data want_id_0034;
input
ID$4. SALE YEAR;
datalines;
0034 35 2003
0034 33 2002
0034 75 2001
0034 32 2000
;
run;
data want_id_2234;
input
ID$4. SALE YEAR;
datalines;
2234 44 2003
2234 22 2003
2234 15 2002
2234 44 2001
2234 44 2000
;
run;

data want_id_8334;
input
ID$4. SALE YEAR;
datalines;
8334 23 2003
8334 44 2002
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;How can I achieve this? I simply find it a little cumberrsome using SQL and WHERE. Since my actual dataset is from 2000 to 2008, there will be a lot of WHERE condition if use SQL.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I am thinking acheive this using MACRO. How can I do this?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Thank you all very much! Appreciate it.&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 21 Mar 2018 00:20:48 GMT</pubDate>
    <dc:creator>yanshuai</dc:creator>
    <dc:date>2018-03-21T00:20:48Z</dc:date>
    <item>
      <title>How to collect obs from several dataset into individual datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-collect-obs-from-several-dataset-into-individual-datasets/m-p/447278#M112309</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have dataset several like this.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have2000 ;
input
ID$4. SALE YEAR;
datalines;
6734 28 2000
1234 23 2000
0034 32 2000
2234 44 2000
;
run;

data have2001 ;
input
ID$4. SALE YEAR;
datalines;
6734 17 2001
1234 52 2001
0034 75 2001
2234 44 2001
1234 26 2001
;
run;

data have2002 ;
input
ID$4. SALE YEAR;
datalines;
6734 11 2002
1234 23 2002
0034 33 2002
2234 15 2002
1234 13 2002
8334 44 2002
;
run;

data have2003 ;
input
ID$4. SALE YEAR;
datalines;
6734 56 2003
1234 43 2003
0034 35 2003
2234 44 2003
1234 45 2003
8334 23 2003
2234 22 2003
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is what I would like to acheive.&lt;/P&gt;&lt;P&gt;Collect all the observation with the same &lt;STRONG&gt;ID&lt;/STRONG&gt; over all dataset I have, and put those observation together in a new dataset and name the new dataset by its &lt;STRONG&gt;ID. Their variable name is basically the same.&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want_id_6734;
input
ID$4. SALE YEAR;
datalines;
6734 56 2003
6734 11 2002
6734 17 2001
6734 28 2000
;
run;

data want_id_1234;
input
ID$4. SALE YEAR;
datalines;
1234 43 2003
1234 45 2003
1234 23 2002
1234 13 2002
1234 52 2001
1234 26 2001
1234 23 2000
;
run;

data want_id_0034;
input
ID$4. SALE YEAR;
datalines;
0034 35 2003
0034 33 2002
0034 75 2001
0034 32 2000
;
run;
data want_id_2234;
input
ID$4. SALE YEAR;
datalines;
2234 44 2003
2234 22 2003
2234 15 2002
2234 44 2001
2234 44 2000
;
run;

data want_id_8334;
input
ID$4. SALE YEAR;
datalines;
8334 23 2003
8334 44 2002
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;How can I achieve this? I simply find it a little cumberrsome using SQL and WHERE. Since my actual dataset is from 2000 to 2008, there will be a lot of WHERE condition if use SQL.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I am thinking acheive this using MACRO. How can I do this?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Thank you all very much! Appreciate it.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 00:20:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-collect-obs-from-several-dataset-into-individual-datasets/m-p/447278#M112309</guid>
      <dc:creator>yanshuai</dc:creator>
      <dc:date>2018-03-21T00:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to collect obs from several dataset into individual datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-collect-obs-from-several-dataset-into-individual-datasets/m-p/447279#M112310</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have2000 ;
input
ID$4. SALE YEAR;
datalines;
6734 28 2000
1234 23 2000
0034 32 2000
2234 44 2000
;
run;

data have2001 ;
input
ID$4. SALE YEAR;
datalines;
6734 17 2001
1234 52 2001
0034 75 2001
2234 44 2001
1234 26 2001
;
run;

data have2002 ;
input
ID$4. SALE YEAR;
datalines;
6734 11 2002
1234 23 2002
0034 33 2002
2234 15 2002
1234 13 2002
8334 44 2002
;
run;

data have2003 ;
input
ID$4. SALE YEAR;
datalines;
6734 56 2003
1234 43 2003
0034 35 2003
2234 44 2003
1234 45 2003
8334 23 2003
2234 22 2003
;
run;

data temp;
set have:;
run;



data _null_ ; 
  dcl hash x() ; 
  x.defineKey ('id') ; 
  x.defineData ('id','h') ; 
  x.defineDone () ; 
  dcl hash h ; 
  do until (z) ; 
    set temp end = z ; 
    if x.find() ne 0 then do ; 
      h = _new_ hash (dataset:'temp(obs=0)', multidata:'y') ;
      h.defineKey ('id') ; 
      h.defineData (all:'y') ; 
      h.defineDone () ; 
      x.add() ; 
    end ; 
    h.add() ; 
  end ; 
  dcl hiter i('x') ; 
  do while (i.next()=0) ; 
    h.output (dataset: cats('id_',id)) ; 
  end ; 
  stop ; 
run ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Mar 2018 00:18:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-collect-obs-from-several-dataset-into-individual-datasets/m-p/447279#M112310</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-03-21T00:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to collect obs from several dataset into individual datasets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-collect-obs-from-several-dataset-into-individual-datasets/m-p/447283#M112313</link>
      <description>&lt;P&gt;Slight suggested modification to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;code, create a view instead.&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 procnames"&gt;data&lt;/SPAN&gt; temp / view=temp&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; have:&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/188461"&gt;@yanshuai&lt;/a&gt;&amp;nbsp;is there a particular reason you're doing this? &amp;nbsp;It's usually never recommended and BY group processing is quite powerful in SAS.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 00:47:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-collect-obs-from-several-dataset-into-individual-datasets/m-p/447283#M112313</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-03-21T00:47:19Z</dc:date>
    </item>
  </channel>
</rss>

