<?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 can I make a new dataset for each set of rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-make-a-new-dataset-for-each-set-of-rows/m-p/18093#M2685</link>
    <description>I have to make a new dataset for each set of rows in a dataset. like a dataset&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Data Set: Trip&lt;BR /&gt;
PersonID     TripID    StrtTime    EndTime&lt;BR /&gt;
0001                1       0830         0900&lt;BR /&gt;
0001                2       0915         1015&lt;BR /&gt;
0001                2       1700         1730&lt;BR /&gt;
0002                1       0700          0800&lt;BR /&gt;
0002                2       0730          0830&lt;BR /&gt;
0002                2       1630          1730&lt;BR /&gt;
   &lt;BR /&gt;
     here I need to create a new dataset for each combination of PersonID And TripID.for eg. for 0001 &amp;amp; 1,there should be differnt dataset and for 0001 &amp;amp; 2,  there should be differnt dataset and so on.&lt;BR /&gt;
 List of combination is dynamic and will be stored in a macro as a comma separated list.and combination will also be variant, i.e. it can have any number of columns.</description>
    <pubDate>Tue, 14 Apr 2009 07:25:34 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-04-14T07:25:34Z</dc:date>
    <item>
      <title>How can I make a new dataset for each set of rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-make-a-new-dataset-for-each-set-of-rows/m-p/18093#M2685</link>
      <description>I have to make a new dataset for each set of rows in a dataset. like a dataset&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Data Set: Trip&lt;BR /&gt;
PersonID     TripID    StrtTime    EndTime&lt;BR /&gt;
0001                1       0830         0900&lt;BR /&gt;
0001                2       0915         1015&lt;BR /&gt;
0001                2       1700         1730&lt;BR /&gt;
0002                1       0700          0800&lt;BR /&gt;
0002                2       0730          0830&lt;BR /&gt;
0002                2       1630          1730&lt;BR /&gt;
   &lt;BR /&gt;
     here I need to create a new dataset for each combination of PersonID And TripID.for eg. for 0001 &amp;amp; 1,there should be differnt dataset and for 0001 &amp;amp; 2,  there should be differnt dataset and so on.&lt;BR /&gt;
 List of combination is dynamic and will be stored in a macro as a comma separated list.and combination will also be variant, i.e. it can have any number of columns.</description>
      <pubDate>Tue, 14 Apr 2009 07:25:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-make-a-new-dataset-for-each-set-of-rows/m-p/18093#M2685</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-04-14T07:25:34Z</dc:date>
    </item>
    <item>
      <title>Re: How can I make a new dataset for each set of rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-make-a-new-dataset-for-each-set-of-rows/m-p/18094#M2686</link>
      <description>What you ask for can be done but needs quite a bit of macro coding. At least I can't think of an easy way to do it.&lt;BR /&gt;
&lt;BR /&gt;
I can't help but thinking that there must be another approach for your problem. It's normally not a good idea to create a lot of datasets.&lt;BR /&gt;
&lt;BR /&gt;
Can you describe what the problem is you want to solve?&lt;BR /&gt;
&lt;BR /&gt;
Regards, Patrick</description>
      <pubDate>Tue, 14 Apr 2009 09:44:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-make-a-new-dataset-for-each-set-of-rows/m-p/18094#M2686</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2009-04-14T09:44:25Z</dc:date>
    </item>
    <item>
      <title>Re: How can I make a new dataset for each set of rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-make-a-new-dataset-for-each-set-of-rows/m-p/18095#M2687</link>
      <description>I agree with Patrick, generating many datasets are not a good thing to do (it should be "neater" if you could process the dataset at once without splitting it), but here's an "ugly" (call execute) but simple way of doing it without the complexity of macro coding.&lt;BR /&gt;
&lt;BR /&gt;
Assuming that Trip is ordered by PersonID and TripID:&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
set Trip;&lt;BR /&gt;
retain _FIRSTOBS;&lt;BR /&gt;
by PersonID TripID; /* assume that Trip is ordered */&lt;BR /&gt;
if first.TripID then do; /* first pair */&lt;BR /&gt;
_FIRSTOBS=_N_; /* hold the obs num */&lt;BR /&gt;
_COMBNUM+1; /* count combination number */&lt;BR /&gt;
end;&lt;BR /&gt;
if last.TripID then do; /* last pair */&lt;BR /&gt;
call execute('data COMB'!!cats(put(_COMBNUM,best.))!!&lt;BR /&gt;
             '; set x (firstobs='!!cats(put(_FIRSTOBS,best.))!!' obs = '!!cats(put(_N_,best.))!!'); run;'); /* slice the dataset with call execute call */&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Caution, at the end you'll have many COMBx datasets (one per combination).&lt;BR /&gt;
&lt;BR /&gt;
Greetings from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos at &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;</description>
      <pubDate>Tue, 14 Apr 2009 10:44:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-make-a-new-dataset-for-each-set-of-rows/m-p/18095#M2687</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-04-14T10:44:25Z</dc:date>
    </item>
  </channel>
</rss>

