<?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: subsetting data set due to no of obs in another one in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/subsetting-data-set-due-to-no-of-obs-in-another-one/m-p/42930#M5075</link>
    <description>change the variable name CNT in data one appropriately, and use PROC SURVEYSELECT with strata&lt;BR /&gt;
&lt;BR /&gt;
check the manual of SURVEYSELECT</description>
    <pubDate>Mon, 04 Apr 2011 15:00:18 GMT</pubDate>
    <dc:creator>oloolo</dc:creator>
    <dc:date>2011-04-04T15:00:18Z</dc:date>
    <item>
      <title>subsetting data set due to no of obs in another one</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/subsetting-data-set-due-to-no-of-obs-in-another-one/m-p/42928#M5073</link>
      <description>Dear,&lt;BR /&gt;
&lt;BR /&gt;
I have two data set as follow:&lt;BR /&gt;
&lt;BR /&gt;
one                                                      ID CNT&lt;BR /&gt;
1   2&lt;BR /&gt;
2   1&lt;BR /&gt;
&lt;BR /&gt;
Two&lt;BR /&gt;
  ID Qnty Price&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
    1    50     20&lt;BR /&gt;
    1    15      7&lt;BR /&gt;
    1     18     40&lt;BR /&gt;
    1     14     80&lt;BR /&gt;
    2     18      70&lt;BR /&gt;
    2     15     41&lt;BR /&gt;
&lt;BR /&gt;
how can I select number of observations from data set two as per CNT from data set one. it means I want to select only two observations from data set two has ID 1. and only 1 observation from data set two has ID 2

Message was edited by: Mohamed</description>
      <pubDate>Sun, 03 Apr 2011 10:51:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/subsetting-data-set-due-to-no-of-obs-in-another-one/m-p/42928#M5073</guid>
      <dc:creator>Mohamed</dc:creator>
      <dc:date>2011-04-03T10:51:24Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting data set due to no of obs in another one</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/subsetting-data-set-due-to-no-of-obs-in-another-one/m-p/42929#M5074</link>
      <description>Hi,&lt;BR /&gt;
From Your description i dont understand, for example how you choose the  two observations from data set two has ID 1???&lt;BR /&gt;
 In my soulotion i assumed you want to choose  the first onces:&lt;BR /&gt;
&lt;BR /&gt;
options symbolgen mprint;&lt;BR /&gt;
&lt;BR /&gt;
data one;&lt;BR /&gt;
input ID CNT;&lt;BR /&gt;
cards&lt;BR /&gt;
;&lt;BR /&gt;
1 2&lt;BR /&gt;
2 1&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
*count the numbers of id's in table one;&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
select count(*)&lt;BR /&gt;
into: num&lt;BR /&gt;
from one&lt;BR /&gt;
;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
select id,cnt&lt;BR /&gt;
into: var1-:var%sysfunc(compress(&amp;amp;num)),:cnt separated by '*'&lt;BR /&gt;
from one&lt;BR /&gt;
;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data Two;&lt;BR /&gt;
input ID Qnty Price;&lt;BR /&gt;
cards;&lt;BR /&gt;
1 50 20&lt;BR /&gt;
1 15 7&lt;BR /&gt;
1 18 40&lt;BR /&gt;
1 14 80&lt;BR /&gt;
2 18 70&lt;BR /&gt;
2 15 41&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%macro example;&lt;BR /&gt;
%do i=1 %to &amp;amp;num;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table _tosplit_&amp;amp;i  as&lt;BR /&gt;
select *&lt;BR /&gt;
from two&lt;BR /&gt;
where ID=&amp;amp;&amp;amp;var&amp;amp;i&lt;BR /&gt;
;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
data _tossplit_&amp;amp;i ;&lt;BR /&gt;
set _tosplit_&amp;amp;i  (obs=%scan(&amp;amp;cnt,&amp;amp;i,*));&lt;BR /&gt;
run;&lt;BR /&gt;
	%if &amp;amp;i=1 %then %do;&lt;BR /&gt;
	data all;&lt;BR /&gt;
	set _tossplit_&amp;amp;i;&lt;BR /&gt;
	run;&lt;BR /&gt;
	%end;&lt;BR /&gt;
	%else %do;&lt;BR /&gt;
	proc append base=all&lt;BR /&gt;
	            data=_tossplit_&amp;amp;i&lt;BR /&gt;
				;&lt;BR /&gt;
	run;&lt;BR /&gt;
	%end;&lt;BR /&gt;
&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%mend examle;&lt;BR /&gt;
%example;&lt;BR /&gt;
&lt;BR /&gt;
Good Luck</description>
      <pubDate>Mon, 04 Apr 2011 13:00:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/subsetting-data-set-due-to-no-of-obs-in-another-one/m-p/42929#M5074</guid>
      <dc:creator>yonib</dc:creator>
      <dc:date>2011-04-04T13:00:30Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting data set due to no of obs in another one</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/subsetting-data-set-due-to-no-of-obs-in-another-one/m-p/42930#M5075</link>
      <description>change the variable name CNT in data one appropriately, and use PROC SURVEYSELECT with strata&lt;BR /&gt;
&lt;BR /&gt;
check the manual of SURVEYSELECT</description>
      <pubDate>Mon, 04 Apr 2011 15:00:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/subsetting-data-set-due-to-no-of-obs-in-another-one/m-p/42930#M5075</guid>
      <dc:creator>oloolo</dc:creator>
      <dc:date>2011-04-04T15:00:18Z</dc:date>
    </item>
  </channel>
</rss>

