<?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: unique observation count in SAS Data Science</title>
    <link>https://communities.sas.com/t5/SAS-Data-Science/unique-observation-count/m-p/179605#M2136</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;&amp;nbsp; input id type$ city$;&lt;BR /&gt;datalines;&lt;BR /&gt;101 saving&amp;nbsp;&amp;nbsp; nyj&lt;BR /&gt;101 account&amp;nbsp; nyj&lt;BR /&gt;101 mutual&amp;nbsp;&amp;nbsp; nyj&lt;BR /&gt;102 saving&amp;nbsp;&amp;nbsp; mex&lt;BR /&gt;102 account&amp;nbsp; mex&lt;BR /&gt;102 mutual&amp;nbsp;&amp;nbsp; mex&lt;BR /&gt;103 saving&amp;nbsp;&amp;nbsp; mex&lt;BR /&gt;103 mutual&amp;nbsp;&amp;nbsp; mex&lt;BR /&gt;105 mutual&amp;nbsp;&amp;nbsp; mex&lt;BR /&gt;104 saving&amp;nbsp;&amp;nbsp; mex&lt;BR /&gt;104 saving&amp;nbsp;&amp;nbsp; nyj&lt;BR /&gt;104 mutual&amp;nbsp;&amp;nbsp; nyj&lt;BR /&gt;&amp;nbsp; ;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=have;&lt;BR /&gt;by city id;&lt;BR /&gt;run;&lt;BR /&gt;data want;&lt;BR /&gt;counter_unique_id=0;&lt;BR /&gt; do i=1 by 1 until (last.city);&lt;BR /&gt;&amp;nbsp; set have (drop=type);&lt;BR /&gt; by city id;&lt;BR /&gt;&amp;nbsp; if last.id then counter_unique_id=counter_unique_id+1;&lt;BR /&gt;&amp;nbsp; if last.city then output;&lt;BR /&gt; end;&lt;/P&gt;&lt;P&gt;drop i id;&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Oct 2014 07:48:39 GMT</pubDate>
    <dc:creator>Loko</dc:creator>
    <dc:date>2014-10-10T07:48:39Z</dc:date>
    <item>
      <title>unique observation count</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/unique-observation-count/m-p/179604#M2135</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi gm &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;can any one help me on how to write code for unique observation in one data set based on two variables without using proc sql&lt;/P&gt;&lt;P&gt; mock data set:&lt;/P&gt;&lt;P&gt;&lt;STRONG style="mso-fareast-language: EN-US; color: navy; background: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; mso-fareast-language: EN-US;"&gt; count;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="background: white; color: blue; font-family: 'Courier New'; mso-fareast-language: EN-US;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; mso-fareast-language: EN-US;"&gt; id type$ city$;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;STRONG style="mso-fareast-language: EN-US; color: teal; background: white; font-family: 'Courier New';"&gt;101&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; mso-fareast-language: EN-US;"&gt; saving&amp;nbsp;&amp;nbsp; nyj&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;STRONG style="mso-fareast-language: EN-US; color: teal; background: white; font-family: 'Courier New';"&gt;101&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; mso-fareast-language: EN-US;"&gt; account&amp;nbsp; nyj&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;STRONG style="mso-fareast-language: EN-US; color: teal; background: white; font-family: 'Courier New';"&gt;101&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; mso-fareast-language: EN-US;"&gt; mutual&amp;nbsp;&amp;nbsp; nyj&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;STRONG style="mso-fareast-language: EN-US; color: teal; background: white; font-family: 'Courier New';"&gt;102&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; mso-fareast-language: EN-US;"&gt; saving&amp;nbsp;&amp;nbsp; Mex&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;STRONG style="mso-fareast-language: EN-US; color: teal; background: white; font-family: 'Courier New';"&gt;102&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; mso-fareast-language: EN-US;"&gt; account&amp;nbsp; Mex&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;STRONG style="mso-fareast-language: EN-US; color: teal; background: white; font-family: 'Courier New';"&gt;102&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; mso-fareast-language: EN-US;"&gt; mutual&amp;nbsp;&amp;nbsp; mex&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;STRONG style="mso-fareast-language: EN-US; color: teal; background: white; font-family: 'Courier New';"&gt;103&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; mso-fareast-language: EN-US;"&gt; saving&amp;nbsp;&amp;nbsp; mex&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;STRONG style="mso-fareast-language: EN-US; color: teal; background: white; font-family: 'Courier New';"&gt;103&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; mso-fareast-language: EN-US;"&gt; mutual&amp;nbsp;&amp;nbsp; mex&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;STRONG style="mso-fareast-language: EN-US; color: teal; background: white; font-family: 'Courier New';"&gt;104&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; mso-fareast-language: EN-US;"&gt; saving&amp;nbsp;&amp;nbsp; nyj&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;STRONG style="mso-fareast-language: EN-US; color: teal; background: white; font-family: 'Courier New';"&gt;104&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; mso-fareast-language: EN-US;"&gt; mutual&amp;nbsp;&amp;nbsp; nyj&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="background: white; color: black; font-family: 'Courier New'; mso-fareast-language: EN-US;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;STRONG style="mso-fareast-language: EN-US; color: navy; background: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; mso-fareast-language: EN-US;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background: white; color: green; font-family: 'Courier New'; mso-fareast-language: EN-US;"&gt;/*I nedd result unique count for &lt;STRONG&gt;id&lt;/STRONG&gt;&amp;nbsp; based on varible &lt;STRONG&gt;city&lt;/STRONG&gt;*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: green; font-family: 'Courier New'; mso-fareast-language: EN-US;"&gt;result as expected:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;STRONG style="mso-fareast-language: EN-US; color: teal; background: white; font-family: 'Courier New';"&gt;1.&lt;/STRONG&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; mso-fareast-language: EN-US;"&gt; count of unique id&lt;/SPAN&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New'; mso-fareast-language: EN-US;"&gt;'s&amp;nbsp; (where city=nyj)=&amp;nbsp; 02&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: purple; font-family: 'Courier New'; mso-fareast-language: EN-US;"&gt;2. count of unique id'&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; mso-fareast-language: EN-US;"&gt;s (where city=mex)= 02&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New'; mso-fareast-language: EN-US;"&gt;thanks &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Oct 2014 04:42:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/unique-observation-count/m-p/179604#M2135</guid>
      <dc:creator>RajasekharReddy</dc:creator>
      <dc:date>2014-10-10T04:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: unique observation count</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/unique-observation-count/m-p/179605#M2136</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;&amp;nbsp; input id type$ city$;&lt;BR /&gt;datalines;&lt;BR /&gt;101 saving&amp;nbsp;&amp;nbsp; nyj&lt;BR /&gt;101 account&amp;nbsp; nyj&lt;BR /&gt;101 mutual&amp;nbsp;&amp;nbsp; nyj&lt;BR /&gt;102 saving&amp;nbsp;&amp;nbsp; mex&lt;BR /&gt;102 account&amp;nbsp; mex&lt;BR /&gt;102 mutual&amp;nbsp;&amp;nbsp; mex&lt;BR /&gt;103 saving&amp;nbsp;&amp;nbsp; mex&lt;BR /&gt;103 mutual&amp;nbsp;&amp;nbsp; mex&lt;BR /&gt;105 mutual&amp;nbsp;&amp;nbsp; mex&lt;BR /&gt;104 saving&amp;nbsp;&amp;nbsp; mex&lt;BR /&gt;104 saving&amp;nbsp;&amp;nbsp; nyj&lt;BR /&gt;104 mutual&amp;nbsp;&amp;nbsp; nyj&lt;BR /&gt;&amp;nbsp; ;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=have;&lt;BR /&gt;by city id;&lt;BR /&gt;run;&lt;BR /&gt;data want;&lt;BR /&gt;counter_unique_id=0;&lt;BR /&gt; do i=1 by 1 until (last.city);&lt;BR /&gt;&amp;nbsp; set have (drop=type);&lt;BR /&gt; by city id;&lt;BR /&gt;&amp;nbsp; if last.id then counter_unique_id=counter_unique_id+1;&lt;BR /&gt;&amp;nbsp; if last.city then output;&lt;BR /&gt; end;&lt;/P&gt;&lt;P&gt;drop i id;&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Oct 2014 07:48:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/unique-observation-count/m-p/179605#M2136</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2014-10-10T07:48:39Z</dc:date>
    </item>
    <item>
      <title>Re: unique observation count</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/unique-observation-count/m-p/179606#M2137</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;data have;
&amp;nbsp; input id type$ city$;
datalines;
101 saving&amp;nbsp;&amp;nbsp; nyj
101 account&amp;nbsp; nyj
101 mutual&amp;nbsp;&amp;nbsp; nyj
102 saving&amp;nbsp;&amp;nbsp; mex
102 account&amp;nbsp; mex
102 mutual&amp;nbsp;&amp;nbsp; mex
103 saving&amp;nbsp;&amp;nbsp; mex
103 mutual&amp;nbsp;&amp;nbsp; mex
105 mutual&amp;nbsp;&amp;nbsp; mex
104 saving&amp;nbsp;&amp;nbsp; mex
104 saving&amp;nbsp;&amp;nbsp; nyj
104 mutual&amp;nbsp;&amp;nbsp; nyj
&amp;nbsp; ;
run;
proc sort data=have;
by city id;
run;
ods listing close;
ods output nlevels=want;
proc freq data=have nlevels;
by city;
table id /norow nocol nopercent nocum;
run;
ods listing;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Oct 2014 12:26:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/unique-observation-count/m-p/179606#M2137</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-10-10T12:26:46Z</dc:date>
    </item>
    <item>
      <title>Re: unique observation count</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/unique-observation-count/m-p/179607#M2138</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;proc sort data=have;&lt;BR /&gt;by city;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want(keep=city unique_count);&lt;BR /&gt;set have;&lt;BR /&gt;by city;&lt;BR /&gt;lag_id=id-lag(id);&lt;BR /&gt;if first.city then unique_count=1;&lt;BR /&gt;if not first.city and lag_id ne 0 then unique_count+1;&lt;BR /&gt;if last.city then output;&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Oct 2014 14:43:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/unique-observation-count/m-p/179607#M2138</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2014-10-10T14:43:03Z</dc:date>
    </item>
  </channel>
</rss>

