<?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 display records based on numbers in other dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/display-records-based-on-numbers-in-other-dataset/m-p/289785#M269980</link>
    <description>&lt;P&gt;I have two datasets "A" and "B".&lt;/P&gt;&lt;P&gt;data a;&lt;/P&gt;&lt;P&gt;name age frnds;&lt;/P&gt;&lt;P&gt;raj 12 a&lt;/P&gt;&lt;P&gt;raj 12 b&lt;/P&gt;&lt;P&gt;raj 12 c&lt;/P&gt;&lt;P&gt;rahul 21 a&lt;/P&gt;&lt;P&gt;rahul 21 d&lt;/P&gt;&lt;P&gt;rahul 21 e&lt;/P&gt;&lt;P&gt;rahul 21 f&lt;/P&gt;&lt;P&gt;raj 21 f&lt;/P&gt;&lt;P&gt;raj 21 h...... .... .....&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;like this there are many observations in my data set A.And data set B like&lt;/P&gt;&lt;P&gt;data B;&lt;/P&gt;&lt;P&gt;name age frnds;&lt;/P&gt;&lt;P&gt;raj &amp;nbsp; &amp;nbsp; 12 &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;&lt;P&gt;rahul 21 &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;raj &amp;nbsp; &amp;nbsp; 21 &amp;nbsp; &amp;nbsp;5&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;so from data set "A" I want that much observations as there are numbers in dataset b in "frnds".For ex in data set b for "raj" "12"&lt;/P&gt;&lt;P&gt;there are "4" in frnds so I need first 4 observations from data set A .Similarly for rahul need first 3 observations from data set A&lt;/P&gt;&lt;P&gt;and 5 observations for "raj" "21" from data set A and so on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Final op&lt;/P&gt;&lt;P&gt;name age frnds&lt;/P&gt;&lt;P&gt;raj 12 &amp;nbsp; &amp;nbsp; &amp;nbsp; a&lt;/P&gt;&lt;P&gt;raj 12 &amp;nbsp; &amp;nbsp; &amp;nbsp; b&lt;/P&gt;&lt;P&gt;raj 12 &amp;nbsp; &amp;nbsp; &amp;nbsp; c&lt;/P&gt;&lt;P&gt;raj 12 &amp;nbsp; &amp;nbsp; &amp;nbsp; d &amp;nbsp;&lt;/P&gt;&lt;P&gt;raj 12 &amp;nbsp; &amp;nbsp; &amp;nbsp; e&amp;nbsp;&lt;/P&gt;&lt;P&gt;rahul 21 &amp;nbsp; a&lt;/P&gt;&lt;P&gt;rahul 21 &amp;nbsp; f&lt;/P&gt;&lt;P&gt;rahul 21 &amp;nbsp; g&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and so on.......&lt;/P&gt;</description>
    <pubDate>Fri, 05 Aug 2016 13:03:54 GMT</pubDate>
    <dc:creator>pawandh</dc:creator>
    <dc:date>2016-08-05T13:03:54Z</dc:date>
    <item>
      <title>display records based on numbers in other dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/display-records-based-on-numbers-in-other-dataset/m-p/289785#M269980</link>
      <description>&lt;P&gt;I have two datasets "A" and "B".&lt;/P&gt;&lt;P&gt;data a;&lt;/P&gt;&lt;P&gt;name age frnds;&lt;/P&gt;&lt;P&gt;raj 12 a&lt;/P&gt;&lt;P&gt;raj 12 b&lt;/P&gt;&lt;P&gt;raj 12 c&lt;/P&gt;&lt;P&gt;rahul 21 a&lt;/P&gt;&lt;P&gt;rahul 21 d&lt;/P&gt;&lt;P&gt;rahul 21 e&lt;/P&gt;&lt;P&gt;rahul 21 f&lt;/P&gt;&lt;P&gt;raj 21 f&lt;/P&gt;&lt;P&gt;raj 21 h...... .... .....&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;like this there are many observations in my data set A.And data set B like&lt;/P&gt;&lt;P&gt;data B;&lt;/P&gt;&lt;P&gt;name age frnds;&lt;/P&gt;&lt;P&gt;raj &amp;nbsp; &amp;nbsp; 12 &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;&lt;P&gt;rahul 21 &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;raj &amp;nbsp; &amp;nbsp; 21 &amp;nbsp; &amp;nbsp;5&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;so from data set "A" I want that much observations as there are numbers in dataset b in "frnds".For ex in data set b for "raj" "12"&lt;/P&gt;&lt;P&gt;there are "4" in frnds so I need first 4 observations from data set A .Similarly for rahul need first 3 observations from data set A&lt;/P&gt;&lt;P&gt;and 5 observations for "raj" "21" from data set A and so on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Final op&lt;/P&gt;&lt;P&gt;name age frnds&lt;/P&gt;&lt;P&gt;raj 12 &amp;nbsp; &amp;nbsp; &amp;nbsp; a&lt;/P&gt;&lt;P&gt;raj 12 &amp;nbsp; &amp;nbsp; &amp;nbsp; b&lt;/P&gt;&lt;P&gt;raj 12 &amp;nbsp; &amp;nbsp; &amp;nbsp; c&lt;/P&gt;&lt;P&gt;raj 12 &amp;nbsp; &amp;nbsp; &amp;nbsp; d &amp;nbsp;&lt;/P&gt;&lt;P&gt;raj 12 &amp;nbsp; &amp;nbsp; &amp;nbsp; e&amp;nbsp;&lt;/P&gt;&lt;P&gt;rahul 21 &amp;nbsp; a&lt;/P&gt;&lt;P&gt;rahul 21 &amp;nbsp; f&lt;/P&gt;&lt;P&gt;rahul 21 &amp;nbsp; g&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and so on.......&lt;/P&gt;</description>
      <pubDate>Fri, 05 Aug 2016 13:03:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/display-records-based-on-numbers-in-other-dataset/m-p/289785#M269980</guid>
      <dc:creator>pawandh</dc:creator>
      <dc:date>2016-08-05T13:03:54Z</dc:date>
    </item>
    <item>
      <title>Re: display records based on numbers in other dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/display-records-based-on-numbers-in-other-dataset/m-p/289802#M269981</link>
      <description>&lt;P&gt;Well, I would say that this seems to be a pointless endeavour, you have the data you have, why try to create data which isn't there. &amp;nbsp;Anyway, it can be done:&lt;/P&gt;
&lt;PRE&gt;data datab (drop=frnds);
  set datab;
  do i=1 to frnds;
    output;
  end;
run;

proc sql;
  create table WANT as
  select coalesce(A.NAME,B.NAME) as NAME,
         coalesce(A.AGE,B.AGE) as AGE,
         A.FRNDS
  from   DATAA A
  full join DATAB B
  on     A.NAME=B.NAME 
  and    A.AGE=B.AGE;
quit;
  
    &lt;/PRE&gt;
&lt;P&gt;What this does is expand datab to have as many rows as stipulated in frnds variable. &amp;nbsp;This is then joined onto dataa, using an all to all join, to expand dataa to have the same number of records as datab.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Aug 2016 14:06:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/display-records-based-on-numbers-in-other-dataset/m-p/289802#M269981</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-08-05T14:06:10Z</dc:date>
    </item>
    <item>
      <title>Re: display records based on numbers in other dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/display-records-based-on-numbers-in-other-dataset/m-p/289958#M269982</link>
      <description>&lt;PRE&gt;

data a;
input name $ age frnds $;
cards;
raaj 12 a
raaj 12 b
raaj 12 c
rahul 21 a
rahul 21 d
rahul 21 e
rahul 21 f
raj 21 f
raj 21 h
;
run;
data B;
input name $ age count;
cards;
raaj     12       4
rahul 21   3
raj     21    5
;
run;
data want;
 merge a b;
 by name age;
 if first.age then n=0;
 n+1;
 if n le count;
 drop n count;
run;

&lt;/PRE&gt;</description>
      <pubDate>Sat, 06 Aug 2016 07:26:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/display-records-based-on-numbers-in-other-dataset/m-p/289958#M269982</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-08-06T07:26:02Z</dc:date>
    </item>
  </channel>
</rss>

