<?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: SAS SQL update iterative tables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/SAS-SQL-update-iterative-tables/m-p/129592#M35327</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Why are you generating macro variables?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;What is it that you are actually trying to do?&amp;nbsp; &lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;You do not need to count in advance. Use the automatic macro variable SQLOBS after the select to see how many values were found. &lt;/P&gt;&lt;P&gt;Just set the upper bound on macro variable range larger than the possible answer. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;proc sql noprint;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'courier new', courier;"&gt;select distinct Subcategory &lt;/SPAN&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt; line-height: 1.5em;"&gt;into :C1 - :C999999&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;from candy_sales_summary&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let n=&amp;amp;sqlobs ;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 07 Mar 2013 04:15:07 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2013-03-07T04:15:07Z</dc:date>
    <item>
      <title>SAS SQL update iterative tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-SQL-update-iterative-tables/m-p/129588#M35323</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I have a table of 1500 observations with Subcategory and their Sales value. I want to find out the count of each subcategory group by subcategory in one table.&lt;/P&gt;&lt;P&gt;In total there are 6 unique subcategories.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; proc &lt;/SPAN&gt;&lt;STRONG style=": ; color: #000080; font-size: 10pt; font-family: Consolas;"&gt;sql&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Consolas;"&gt;noprint&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; count(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Consolas;"&gt;distinct&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; Subcategory)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; :n&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; candy_sales_summary;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Consolas;"&gt;distinct&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;(Subcategory)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; :C1 - :C%&lt;STRONG&gt;&lt;EM&gt;left&lt;/EM&gt;&lt;/STRONG&gt;(&amp;amp;n)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; candy_sales_summary;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; %put &amp;amp;n;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; %put &amp;amp;C3;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;I am unable to complete the below code.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;%macro calc;&lt;BR /&gt; %let i = &amp;amp;n;&lt;BR /&gt; %let j = %eval(&amp;amp;n - 1);&lt;BR /&gt; %do %until (&amp;amp;i ge &amp;amp;j);&lt;BR /&gt; proc sql;&lt;BR /&gt; create table Test as&lt;BR /&gt; select Subcategory,count(Subcategory) as Units&lt;BR /&gt; from candy_sales_summary&lt;BR /&gt; where Subcategory in ("&amp;amp;&amp;amp;C&amp;amp;i")&lt;BR /&gt; group by Subcategory&lt;/P&gt;&lt;P&gt; union all&lt;/P&gt;&lt;P&gt; select Subcategory,count(Subcategory) as Units&lt;BR /&gt; from candy_sales_summary&lt;BR /&gt; where Subcategory in ("&amp;amp;&amp;amp;C&amp;amp;j")&lt;BR /&gt; group by Subcategory&lt;BR /&gt; ;&lt;BR /&gt; quit;&lt;BR /&gt; run;&lt;BR /&gt; %end;&lt;BR /&gt;%mend calc;&lt;BR /&gt;%calc;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there any way in sql where I can iteratively append the count of each subcategory in one table&lt;/P&gt;&lt;P&gt;For example when I run this, I get count of only two, when I need all 6 in one table&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select Subcategory,count(Subcategory) as Units&lt;/P&gt;&lt;P&gt;from candy_sales_summary&lt;/P&gt;&lt;P&gt;where Subcategory in ('Mixed')&lt;/P&gt;&lt;P&gt;group by Subcategory&lt;/P&gt;&lt;P&gt;union all&lt;/P&gt;&lt;P&gt;select Subcategory,count(Subcategory) as Units&lt;/P&gt;&lt;P&gt;from candy_sales_summary&lt;/P&gt;&lt;P&gt;where Subcategory in ('Gum')&lt;/P&gt;&lt;P&gt;group by Subcategory&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please help&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Mar 2013 03:26:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-SQL-update-iterative-tables/m-p/129588#M35323</guid>
      <dc:creator>Arimitra</dc:creator>
      <dc:date>2013-03-07T03:26:56Z</dc:date>
    </item>
    <item>
      <title>Re: SAS SQL update iterative tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-SQL-update-iterative-tables/m-p/129589#M35324</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I beg you pardon for the typo error. When I counting the distinct subcategories which I dont know in advance I am using the below:-&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;select count(distinct Subcategory)&lt;/P&gt;&lt;P&gt;into :n&lt;/P&gt;&lt;P&gt;from candy_sales_summary;&lt;/P&gt;&lt;P&gt;select distinct(Subcategory)&lt;/P&gt;&lt;P&gt;into :C1 - :C%left(&amp;amp;n)&lt;/P&gt;&lt;P&gt;from candy_sales_summary;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Mar 2013 03:30:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-SQL-update-iterative-tables/m-p/129589#M35324</guid>
      <dc:creator>Arimitra</dc:creator>
      <dc:date>2013-03-07T03:30:57Z</dc:date>
    </item>
    <item>
      <title>Re: SAS SQL update iterative tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-SQL-update-iterative-tables/m-p/129590#M35325</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc sql;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;select Subcategory,count(Subcategory) as Units&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;from candy_sales_summary&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;where Subcategory in ('Mixed')&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;group by Subcategory&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;union all&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;select Subcategory,count(Subcategory) as Units&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;from candy_sales_summary&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;where Subcategory in ('Gum')&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;group by Subcategory&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;quit;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;should be equivalent to the following where you've removed the where clause. &lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc sql;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;create table want as&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;select Subcategory,count(Subcategory) as Units&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;from candy_sales_summary&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="text-decoration: line-through;"&gt;where Subcategory in ('Gum')&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;group by Subcategory&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;quit;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;You may want to consider proc freq as well. &lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc freq data=candy_sales_summary;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;table subcategory;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Mar 2013 03:33:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-SQL-update-iterative-tables/m-p/129590#M35325</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-03-07T03:33:58Z</dc:date>
    </item>
    <item>
      <title>Re: SAS SQL update iterative tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-SQL-update-iterative-tables/m-p/129591#M35326</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The intent of this query is I dont know how many subcategories to count. so I would need where clause to query which subcategories to count.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Mar 2013 03:54:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-SQL-update-iterative-tables/m-p/129591#M35326</guid>
      <dc:creator>Arimitra</dc:creator>
      <dc:date>2013-03-07T03:54:37Z</dc:date>
    </item>
    <item>
      <title>Re: SAS SQL update iterative tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-SQL-update-iterative-tables/m-p/129592#M35327</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Why are you generating macro variables?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;What is it that you are actually trying to do?&amp;nbsp; &lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;You do not need to count in advance. Use the automatic macro variable SQLOBS after the select to see how many values were found. &lt;/P&gt;&lt;P&gt;Just set the upper bound on macro variable range larger than the possible answer. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;proc sql noprint;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: 'courier new', courier;"&gt;select distinct Subcategory &lt;/SPAN&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt; line-height: 1.5em;"&gt;into :C1 - :C999999&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;from candy_sales_summary&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let n=&amp;amp;sqlobs ;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Mar 2013 04:15:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-SQL-update-iterative-tables/m-p/129592#M35327</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-03-07T04:15:07Z</dc:date>
    </item>
    <item>
      <title>Re: SAS SQL update iterative tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-SQL-update-iterative-tables/m-p/129593#M35328</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;If you have Subcategories shouldn't you have a Category?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;See if you can relate you query to the SASHELP.CARS sample dataset.&lt;/P&gt;&lt;P&gt;This query will show me that there are 2 Makes of Hybrid cars and 3 total models of Hybrid cars.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;proc sql noprint ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;create table want as&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; select type,count(*) as num_makes, sum(num_models) as total_models&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , make,num_models&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; from&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ( select type,make,count(distinct model) as num_models&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from sashelp.cars&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by type, make&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; group by type&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; order by type, make&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;proc print; run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Mar 2013 04:27:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-SQL-update-iterative-tables/m-p/129593#M35328</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-03-07T04:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAS SQL update iterative tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-SQL-update-iterative-tables/m-p/129594#M35329</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Attached is the query, I have tried to create separate tables for each subcategory but I found no way to append them. The output is required in one table.&lt;/P&gt;&lt;P&gt;I am unable to attach the excel file data. Not sure if I have explained my query properly&lt;/P&gt;&lt;P&gt;Please help.&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/11854i51974D47A158BA89/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="Screenshot.JPG" title="Screenshot.JPG" /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Mar 2013 04:49:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-SQL-update-iterative-tables/m-p/129594#M35329</guid>
      <dc:creator>Arimitra</dc:creator>
      <dc:date>2013-03-07T04:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: SAS SQL update iterative tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-SQL-update-iterative-tables/m-p/129595#M35330</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Arimitra, I'm not sure I understood your question but I wrote the attached code that could be useful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In general, the code does this:&lt;BR /&gt;Step 1: Create sample data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Step 2: Generate a table that shows the count of subcategories and the total sales amount per each subcategory, everything grouped by date. To achieve this result I did the following:&lt;/P&gt;&lt;P&gt;2.1. Extract a list of distinct subcategories values.&lt;/P&gt;&lt;P&gt;2.2. Extract a list of disctinct dates.&lt;/P&gt;&lt;P&gt;2.3. Perform a cross join in order to generate a list with all posible combinations of subcategories per date.&lt;/P&gt;&lt;P&gt;2.4. Calculate a table with the count of subcategories per date and their corresponding total sales amount.&lt;/P&gt;&lt;P&gt;2.5. Perform a left join in order to complement the table from step 2.3 with its matching subcategory count and total sales amount. As we don't have subcategories for all dates you'll get a missing value for those cases.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You may find this process long, and your original question was related to having one single query to achive the result. In response to this question, you can take a look on the next step.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Step 3: This piece of code is a way to have a single query to do the previous steps, it involves subqueries and Cartesian products, but it is NOT a viable solution and I wouldn't suggest by any means use of it, because of the mentioned Cartesian products and remerging (iterative) processes involved. It is not a good practice and you shouldn't consider it for a real implementation, in fact, step 2.3 will generate a Cartesian product so please keep in mind only steps 1 and 2, they can be considered as a possible solution for this example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Oscar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Mar 2013 07:45:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-SQL-update-iterative-tables/m-p/129595#M35330</guid>
      <dc:creator>OscarHernandez</dc:creator>
      <dc:date>2013-03-07T07:45:21Z</dc:date>
    </item>
    <item>
      <title>Re: SAS SQL update iterative tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-SQL-update-iterative-tables/m-p/129596#M35331</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;SPAN class="j-post-author"&gt;&lt;STRONG&gt;&lt;A _jive_internal="true" class="jiveTT-hover-user jive-username-link" data-avatarid="-1" data-externalid="" data-presence="null" data-userid="813553" data-username="Arimitra" href="https://communities.sas.com/people/Arimitra" id="jive-81355363133159896972803"&gt;Arimitra&lt;/A&gt;,&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;STRONG&gt;I think it quite easy by using DATA step rather than complex query...Based on your .JPG file, the output you want is the Total Count of distinct subcategories as well as SUM of distinct categories...&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;STRONG&gt;Please try the following SAS Code...&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;STRONG&gt;proc sort data = have;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by subcategory;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;STRONG&gt;data want;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by subcategory;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if first.subcategory then do;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count = 0;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; total_sales = sales;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else do;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count + 1;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; total_sales + sales;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if last.subcategory;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And ya one more thing to say in this case is that if you supply COUNT(DISTINCT Subcategory) then SAS has to two pass through the data that is one time it will remove the duplicates and then in second pass it will count...So of cource if you have more subcategories then it will take much and muchhh time....So either use Proc Freq or Proc Sort followed by Data Step...&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Urvish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Mar 2013 09:11:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-SQL-update-iterative-tables/m-p/129596#M35331</guid>
      <dc:creator>UrvishShah</dc:creator>
      <dc:date>2013-03-07T09:11:20Z</dc:date>
    </item>
  </channel>
</rss>

