<?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 Proc Sql Summary in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Sql-Summary/m-p/69886#M20105</link>
    <description>Hoping I can get some ideas on how to do a summary report in proc sql.  Here's what I am trying to create:&lt;BR /&gt;
&lt;BR /&gt;
I have a dataset with multiple records for every sales agent. In addition, I have for the columns a number of different company ID's - all the company ID's have a prefix of Firm_ followed by the company id - for example - Firm_XYZ3D - there could be as many as 1000 company ids. The company id columns contains the sales for these companies that are associated with each sales agent. I need to create a summary report that shows every distinct sales agent ID and the the number of non-zero company IDs he or she is associated with.  In addition I also need to determine the total sales per each company ID for every distinct sales agent.&lt;BR /&gt;
&lt;BR /&gt;
Using proc sql to sum/count each distinct company id for every sales agent is quite laborious. &lt;BR /&gt;
&lt;BR /&gt;
Does anyone have any thoughts on how I might approach this. I would greatly appreciate any feedback.</description>
    <pubDate>Mon, 22 Mar 2010 00:55:09 GMT</pubDate>
    <dc:creator>SAS09</dc:creator>
    <dc:date>2010-03-22T00:55:09Z</dc:date>
    <item>
      <title>Proc Sql Summary</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Sql-Summary/m-p/69886#M20105</link>
      <description>Hoping I can get some ideas on how to do a summary report in proc sql.  Here's what I am trying to create:&lt;BR /&gt;
&lt;BR /&gt;
I have a dataset with multiple records for every sales agent. In addition, I have for the columns a number of different company ID's - all the company ID's have a prefix of Firm_ followed by the company id - for example - Firm_XYZ3D - there could be as many as 1000 company ids. The company id columns contains the sales for these companies that are associated with each sales agent. I need to create a summary report that shows every distinct sales agent ID and the the number of non-zero company IDs he or she is associated with.  In addition I also need to determine the total sales per each company ID for every distinct sales agent.&lt;BR /&gt;
&lt;BR /&gt;
Using proc sql to sum/count each distinct company id for every sales agent is quite laborious. &lt;BR /&gt;
&lt;BR /&gt;
Does anyone have any thoughts on how I might approach this. I would greatly appreciate any feedback.</description>
      <pubDate>Mon, 22 Mar 2010 00:55:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Sql-Summary/m-p/69886#M20105</guid>
      <dc:creator>SAS09</dc:creator>
      <dc:date>2010-03-22T00:55:09Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Summary</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Sql-Summary/m-p/69887#M20106</link>
      <description>So do you have around 1000 columns in your table, if I understand you right?&lt;BR /&gt;
To do this in SQL is quite hard. I suggest that transpose your data so that you'll have a company column with the different company id's, and a column for sales for each combination of sales rep and company id. You could use PROC TRANSPOSE or a data step to accomplish this.&lt;BR /&gt;
Then you could use SQL to do the summary report.&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Tue, 23 Mar 2010 13:27:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Sql-Summary/m-p/69887#M20106</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2010-03-23T13:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Summary</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Sql-Summary/m-p/69888#M20107</link>
      <description>seems you have a variable to present each company, so you may like to define a array to include all companys and use a do loop over the array to check no missing sale value for the company.&lt;BR /&gt;
ie.&lt;BR /&gt;
proc sort data = yourdata;&lt;BR /&gt;
by saleID;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
select name into: companys separated by ' ' &lt;BR /&gt;
from dictionary.columns &lt;BR /&gt;
where libname eq "WORK" AND MEMNAME eq "YOURDATA" &lt;BR /&gt;
and name like "Firm_%";&lt;BR /&gt;
quit;&lt;BR /&gt;
%let numc = &amp;amp;sqlobs.;&lt;BR /&gt;
data new;&lt;BR /&gt;
set yourdata;&lt;BR /&gt;
by saleID;&lt;BR /&gt;
array company(&amp;amp;numc) &amp;amp;companys.;&lt;BR /&gt;
array flag(&amp;amp;numc);&lt;BR /&gt;
array sums(&amp;amp;numc);&lt;BR /&gt;
retain flag: sums:;&lt;BR /&gt;
drop i flag: sums:;&lt;BR /&gt;
if first.saleID then do i=1 to &amp;amp;numc.;&lt;BR /&gt;
flag(i)=0;&lt;BR /&gt;
sums(i)=0;&lt;BR /&gt;
end;&lt;BR /&gt;
do i=1 to &amp;amp;numc;&lt;BR /&gt;
if not missing(company(i)) then flag(i)=1;&lt;BR /&gt;
sums(i)=sum(sums(i),company(i));&lt;BR /&gt;
end;&lt;BR /&gt;
if last.saleID then do;&lt;BR /&gt;
noe_zero=sum(of flag:);&lt;BR /&gt;
do i=1 To &amp;amp;numc;&lt;BR /&gt;
company(i)=sums(i);&lt;BR /&gt;
end;&lt;BR /&gt;
output;&lt;BR /&gt;
end;&lt;BR /&gt;
run;</description>
      <pubDate>Wed, 24 Mar 2010 19:45:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Sql-Summary/m-p/69888#M20107</guid>
      <dc:creator>SUN59338</dc:creator>
      <dc:date>2010-03-24T19:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sql Summary</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Sql-Summary/m-p/69889#M20108</link>
      <description>Would this help? &lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
&lt;BR /&gt;
proc summary data=MYDATA nway;&lt;BR /&gt;
  class ID;&lt;BR /&gt;
  var FIRM_:;&lt;BR /&gt;
  output out=TOTAL_SALES(drop=_:) sum=;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data NB_FIRMS(drop=J);&lt;BR /&gt;
  set TOTAL_SALES;&lt;BR /&gt;
  array X &lt;LI&gt; FIRM_:;&lt;BR /&gt;
  do J=1 to dim(X);&lt;BR /&gt;
    NB_FIRMS=sum(NB_FIRMS, X&lt;J&gt; &amp;gt; 0);&lt;BR /&gt;
  end;&lt;BR /&gt;
  *rather than the loop above, use this if you have missing values when there is no sales;&lt;BR /&gt;
  NB_FIRMS2=n(of X&lt;/J&gt;&lt;/LI&gt;&lt;LI&gt;); &lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
proc sql cannot use the colon in this manner unfortunately, and if you must use sql you'll have to create a macro variable containing the list of variables as the previous post shows.&lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: Chris@NewZealand&lt;BR /&gt;
&lt;BR /&gt;
Simplified the reply.&lt;/LI&gt;</description>
      <pubDate>Wed, 24 Mar 2010 23:19:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Sql-Summary/m-p/69889#M20108</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2010-03-24T23:19:32Z</dc:date>
    </item>
  </channel>
</rss>

