<?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 to display all records captured by count function in sql query in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-display-all-records-captured-by-count-function-in-sql/m-p/876991#M346448</link>
    <description>&lt;P&gt;&lt;SPAN&gt;Below is the pass-thru sql query in SAS that I am aiming to modify to display more than two customer records in the same row (by adding additional columns as Name_Example_3, Name_example_4 and so on). The output table below is only displaying two customer records at the moment (using the min and max function). Is there any way I can add more columns if say cus_count &amp;gt;2.&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class=""&gt;&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;sql&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;create table test as&lt;/P&gt;&lt;P&gt;select&lt;/P&gt;&lt;P&gt;ID_TYP,&lt;/P&gt;&lt;P&gt;CUST_ID,&lt;/P&gt;&lt;P&gt;count(distinct(a.number)) as cus_count,&lt;/P&gt;&lt;P&gt;count(distinct(a.name)) as Name_Count,&lt;/P&gt;&lt;P&gt;count(distinct(a.DOB)) as DOB_Count,&lt;/P&gt;&lt;P&gt;min(b.NAME) as Name_Example_1,&lt;/P&gt;&lt;P&gt;max(b.NAME) as Name_Example_2,&lt;/P&gt;&lt;P&gt;min(a.number) as cus1,&lt;/P&gt;&lt;P&gt;max(a.number) as cus2,&lt;/P&gt;&lt;P&gt;min(a.ADDED_DT) as cus1_created_date,&lt;/P&gt;&lt;P&gt;max(a.ADDED_DT) as cus2_created_Date,&lt;/P&gt;&lt;P&gt;count(distinct(c.acc_id)) as acc_count&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;from a left join b&lt;/P&gt;&lt;P&gt;on&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="http://a.sk/" target="_blank" rel="nofollow noopener"&gt;a.SK&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;=&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="http://b.sk/" target="_blank" rel="nofollow noopener"&gt;b.sk&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;left join c&lt;/P&gt;&lt;P&gt;on a.sk_from =&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="http://c.sk/" target="_blank" rel="nofollow noopener"&gt;c.sk&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where&lt;/P&gt;&lt;P&gt;*some condition*&lt;/P&gt;&lt;P&gt;group by CUST_ID_TYP, CUST_ID&lt;/P&gt;&lt;P&gt;having cus_count &amp;gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output table below (First row is the header with corresponding values in the second row):&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID_TYP CUST_ID cus_count Name_Count DOB_Count Name_Example_1 Name_Example_2 cus1 cus2 cus1_created_date cus2_created_Date acc_count&lt;/P&gt;&lt;P&gt;NS ABC 2 2 1 Dummy_cus1 Dummy_cus 2 #1 #2 14072022 10022021 4&lt;/P&gt;&lt;/DIV&gt;</description>
    <pubDate>Tue, 23 May 2023 05:45:24 GMT</pubDate>
    <dc:creator>waliaa</dc:creator>
    <dc:date>2023-05-23T05:45:24Z</dc:date>
    <item>
      <title>How to display all records captured by count function in sql query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-display-all-records-captured-by-count-function-in-sql/m-p/876991#M346448</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Below is the pass-thru sql query in SAS that I am aiming to modify to display more than two customer records in the same row (by adding additional columns as Name_Example_3, Name_example_4 and so on). The output table below is only displaying two customer records at the moment (using the min and max function). Is there any way I can add more columns if say cus_count &amp;gt;2.&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class=""&gt;&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;sql&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;create table test as&lt;/P&gt;&lt;P&gt;select&lt;/P&gt;&lt;P&gt;ID_TYP,&lt;/P&gt;&lt;P&gt;CUST_ID,&lt;/P&gt;&lt;P&gt;count(distinct(a.number)) as cus_count,&lt;/P&gt;&lt;P&gt;count(distinct(a.name)) as Name_Count,&lt;/P&gt;&lt;P&gt;count(distinct(a.DOB)) as DOB_Count,&lt;/P&gt;&lt;P&gt;min(b.NAME) as Name_Example_1,&lt;/P&gt;&lt;P&gt;max(b.NAME) as Name_Example_2,&lt;/P&gt;&lt;P&gt;min(a.number) as cus1,&lt;/P&gt;&lt;P&gt;max(a.number) as cus2,&lt;/P&gt;&lt;P&gt;min(a.ADDED_DT) as cus1_created_date,&lt;/P&gt;&lt;P&gt;max(a.ADDED_DT) as cus2_created_Date,&lt;/P&gt;&lt;P&gt;count(distinct(c.acc_id)) as acc_count&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;from a left join b&lt;/P&gt;&lt;P&gt;on&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="http://a.sk/" target="_blank" rel="nofollow noopener"&gt;a.SK&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;=&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="http://b.sk/" target="_blank" rel="nofollow noopener"&gt;b.sk&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;left join c&lt;/P&gt;&lt;P&gt;on a.sk_from =&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="http://c.sk/" target="_blank" rel="nofollow noopener"&gt;c.sk&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where&lt;/P&gt;&lt;P&gt;*some condition*&lt;/P&gt;&lt;P&gt;group by CUST_ID_TYP, CUST_ID&lt;/P&gt;&lt;P&gt;having cus_count &amp;gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output table below (First row is the header with corresponding values in the second row):&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID_TYP CUST_ID cus_count Name_Count DOB_Count Name_Example_1 Name_Example_2 cus1 cus2 cus1_created_date cus2_created_Date acc_count&lt;/P&gt;&lt;P&gt;NS ABC 2 2 1 Dummy_cus1 Dummy_cus 2 #1 #2 14072022 10022021 4&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 23 May 2023 05:45:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-display-all-records-captured-by-count-function-in-sql/m-p/876991#M346448</guid>
      <dc:creator>waliaa</dc:creator>
      <dc:date>2023-05-23T05:45:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to display all records captured by count function in sql query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-display-all-records-captured-by-count-function-in-sql/m-p/876994#M346450</link>
      <description>&lt;P&gt;Don't do it. Bad idea and waist of time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead do it like this:&lt;/P&gt;
&lt;P&gt;1) collect SQL data in the "long" form&lt;/P&gt;
&lt;P&gt;2) get them to SAS&lt;/P&gt;
&lt;P&gt;3) use proc transpose&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With this approach you will automatically get data in the "wide" form regardless the number of duplicates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2023 06:31:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-display-all-records-captured-by-count-function-in-sql/m-p/876994#M346450</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-05-23T06:31:21Z</dc:date>
    </item>
  </channel>
</rss>

