<?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: How to select count of distinct key based on indicator in another column? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-select-count-of-distinct-key-based-on-indicator-in/m-p/207264#M51482</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here you go, I changed a little. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input geo_key $ var1 var2 var3 var4 var5 var6;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;001 1 1 1 1 1 0&lt;/P&gt;&lt;P&gt;002 1 1 1 1 0 0&lt;/P&gt;&lt;P&gt;003 1 1 1 0 0 0&lt;/P&gt;&lt;P&gt;004 1 1 0 0 0 0&lt;/P&gt;&lt;P&gt;005 1 0 0 0 0 0&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc transpose data=have out=prep;by geo_key;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table want as&lt;/P&gt;&lt;P&gt;select distinct geo_key,sum(col1) as result&lt;/P&gt;&lt;P&gt;from prep&lt;/P&gt;&lt;P&gt;group by geo_key&lt;/P&gt;&lt;P&gt;order by geo_key;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 16 Jun 2015 15:45:32 GMT</pubDate>
    <dc:creator>Steelers_In_DC</dc:creator>
    <dc:date>2015-06-16T15:45:32Z</dc:date>
    <item>
      <title>How to select count of distinct key based on indicator in another column?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-select-count-of-distinct-key-based-on-indicator-in/m-p/207259#M51477</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a table which is like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Geo_Key Var1-Var50(where Var1-Var50 represents 50 columns having value 1/0)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to select count of distinct Geo_Key for each column, when its value is=1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So Results would be like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Var1 50&lt;/P&gt;&lt;P&gt;Var2 60&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;Var50 10&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I only know the exhaustive method, where maybe i can run a macro for 50 variables, to select count for each one. But that would require too much coding. I am sure there must be a better way.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jun 2015 13:45:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-select-count-of-distinct-key-based-on-indicator-in/m-p/207259#M51477</guid>
      <dc:creator>munitech4u</dc:creator>
      <dc:date>2015-06-16T13:45:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to select count of distinct key based on indicator in another column?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-select-count-of-distinct-key-based-on-indicator-in/m-p/207260#M51478</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a shortened version but this should help:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input geo_key var1 var2 var3 var4 var5 var6;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 1 0 0 0 0 0&lt;/P&gt;&lt;P&gt;2 0 0 0 0 0 0&lt;/P&gt;&lt;P&gt;3 1 1 1 1 1 1&lt;/P&gt;&lt;P&gt;4 0 0 1 0 1 0&lt;/P&gt;&lt;P&gt;5 1 0 1 0 1 0&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc transpose data=have out=prep;by geo_key;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table want as&lt;/P&gt;&lt;P&gt;select distinct geo_key,sum(col1) as result&lt;/P&gt;&lt;P&gt;from prep&lt;/P&gt;&lt;P&gt;group by geo_key;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jun 2015 14:04:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-select-count-of-distinct-key-based-on-indicator-in/m-p/207260#M51478</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-06-16T14:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to select count of distinct key based on indicator in another column?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-select-count-of-distinct-key-based-on-indicator-in/m-p/207261#M51479</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This gives the count by geo_key. I need count of geo_key by variables var1-var50.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jun 2015 15:04:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-select-count-of-distinct-key-based-on-indicator-in/m-p/207261#M51479</guid>
      <dc:creator>munitech4u</dc:creator>
      <dc:date>2015-06-16T15:04:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to select count of distinct key based on indicator in another column?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-select-count-of-distinct-key-based-on-indicator-in/m-p/207262#M51480</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Slight variation, this should do it:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input geo_key var1 var2 var3 var4 var5 var6;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 1 0 0 0 0 0&lt;/P&gt;&lt;P&gt;2 0 0 0 0 0 0&lt;/P&gt;&lt;P&gt;3 1 1 1 1 1 1&lt;/P&gt;&lt;P&gt;4 0 0 1 0 1 0&lt;/P&gt;&lt;P&gt;5 1 0 1 0 1 0&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc transpose data=have out=prep;by geo_key;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table want as&lt;/P&gt;&lt;P&gt;select distinct _name_,sum(col1) as result&lt;/P&gt;&lt;P&gt;from prep&lt;/P&gt;&lt;P&gt;group by _name_&lt;/P&gt;&lt;P&gt;order by _name_;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jun 2015 15:11:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-select-count-of-distinct-key-based-on-indicator-in/m-p/207262#M51480</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-06-16T15:11:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to select count of distinct key based on indicator in another column?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-select-count-of-distinct-key-based-on-indicator-in/m-p/207263#M51481</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The problem is that geo_key might be repeated(so I am having multiple columns), so i want to count the distinct value of it, when indicator is 1 for that variable. So scenario will change for each variable. So basically I want the count to match to below query:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select count(distinct geo_key) from table where var1=1;&lt;/P&gt;&lt;P&gt;select count(distinct geo_key) from table where var2=1;&lt;/P&gt;&lt;P&gt;.....&lt;/P&gt;&lt;P&gt;select count(distinct geo_key) from table where var50=1;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jun 2015 15:30:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-select-count-of-distinct-key-based-on-indicator-in/m-p/207263#M51481</guid>
      <dc:creator>munitech4u</dc:creator>
      <dc:date>2015-06-16T15:30:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to select count of distinct key based on indicator in another column?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-select-count-of-distinct-key-based-on-indicator-in/m-p/207264#M51482</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here you go, I changed a little. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input geo_key $ var1 var2 var3 var4 var5 var6;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;001 1 1 1 1 1 0&lt;/P&gt;&lt;P&gt;002 1 1 1 1 0 0&lt;/P&gt;&lt;P&gt;003 1 1 1 0 0 0&lt;/P&gt;&lt;P&gt;004 1 1 0 0 0 0&lt;/P&gt;&lt;P&gt;005 1 0 0 0 0 0&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc transpose data=have out=prep;by geo_key;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table want as&lt;/P&gt;&lt;P&gt;select distinct geo_key,sum(col1) as result&lt;/P&gt;&lt;P&gt;from prep&lt;/P&gt;&lt;P&gt;group by geo_key&lt;/P&gt;&lt;P&gt;order by geo_key;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jun 2015 15:45:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-select-count-of-distinct-key-based-on-indicator-in/m-p/207264#M51482</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-06-16T15:45:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to select count of distinct key based on indicator in another column?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-select-count-of-distinct-key-based-on-indicator-in/m-p/207265#M51483</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your help. Since there can be duplicates for the geo_key. Its giving me multiple columns around col1-col50. So just summing across col1 wont solve my problem. So i summed across all rows and set a new indicator to 1 if value is &amp;gt;=1. and then summed on that variables, which seems to be doing the job.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jun 2015 15:54:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-select-count-of-distinct-key-based-on-indicator-in/m-p/207265#M51483</guid>
      <dc:creator>munitech4u</dc:creator>
      <dc:date>2015-06-16T15:54:02Z</dc:date>
    </item>
  </channel>
</rss>

