<?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: Creating running total in EG (Top N) in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-running-total-in-EG/m-p/6648#M2113</link>
    <description>Here is a more formal example for creating Top N reports in SAS and in SAS Enterprise Guide.  The example includes SAS programs, and also includes a custom task for EG so you can avoid the programming, if you want.&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/kb/33/009.html" target="_blank"&gt;http://support.sas.com/kb/33/009.html&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Chris</description>
    <pubDate>Fri, 29 Aug 2008 02:10:00 GMT</pubDate>
    <dc:creator>ChrisHemedinger</dc:creator>
    <dc:date>2008-08-29T02:10:00Z</dc:date>
    <item>
      <title>Creating running total in EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-running-total-in-EG/m-p/6643#M2108</link>
      <description>I am new to EG although I am an experienced SAS user. I have a code that I wrote to identify top 50 observations based on my sort criteria. I would like to know how I can accomplish this task in EG without writing the code. Here is the code:&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=A;&lt;BR /&gt;
	by X Y Z;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data top50;&lt;BR /&gt;
	set A;&lt;BR /&gt;
	by X Y Z;&lt;BR /&gt;
	retain count;&lt;BR /&gt;
	if first.X then count=1;&lt;BR /&gt;
	else count = count+1;&lt;BR /&gt;
	if count &amp;lt;=50;&lt;BR /&gt;
	drop count;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your help!

if count &amp;lt;=50;&lt;BR /&gt;
	drop count;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: DavidW</description>
      <pubDate>Tue, 29 Jan 2008 20:04:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-running-total-in-EG/m-p/6643#M2108</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-01-29T20:04:20Z</dc:date>
    </item>
    <item>
      <title>Re: Creating running total in EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-running-total-in-EG/m-p/6644#M2109</link>
      <description>I do this a lot, especially when I need to limit a transpose to 20 things for charting.&lt;BR /&gt;
&lt;BR /&gt;
1)  Use a query to select the columns and basic values/things of interest&lt;BR /&gt;
2)  In the query's sort tap, add the value/thing of interest and set it to descending sort order&lt;BR /&gt;
3)  In the upper rightish area of the query dialog box/window is a drop list/button titled "options";  Select "Options for this Query".&lt;BR /&gt;
4)  In the resulting "Results Options" popup dialog box, near the bottom, select the "Limit output rows:" check box, and put the number of rows desired to be returned in the edit field on the right.&lt;BR /&gt;
5)  Click "Ok" then click "Run"&lt;BR /&gt;
&lt;BR /&gt;
Let's say you create a query like the following:&lt;BR /&gt;
&lt;BR /&gt;
select host, command, datetime, max(utilization) as max_of_utilization&lt;BR /&gt;
  from performance_metrics&lt;BR /&gt;
  group by host, command, datetime;&lt;BR /&gt;
&lt;BR /&gt;
and you want the top 50 commands with the most utilization.&lt;BR /&gt;
This is easily created in the query form (no code) including the addition of&lt;BR /&gt;
&lt;BR /&gt;
sort by max_of_utilization descending;&lt;BR /&gt;
&lt;BR /&gt;
In the query dialog box, you add utilization to the "Select Data" tab and then under the summary column select "MAX" and SAS EG will add a "Computed Column" to the list of columns available.  Then on the "Sort Data" tab you add "MAX_OF_Utilization" and select Descending in its "Sort Direction" column.&lt;BR /&gt;
&lt;BR /&gt;
Now you can change the options for that query to limit output to 50 rows.&lt;BR /&gt;
&lt;BR /&gt;
With that, you can now create a new query to join back to the original dataset and act as filter to select all the records related to the selected top50 commands.&lt;BR /&gt;
&lt;BR /&gt;
To help with the join, I would recommend you change the name of the output from the select top 50 query to "TOP50_COMMANDS".  This is done by clicking on the "CHANGE" button at the top of the query box for the "Output name:"&lt;BR /&gt;
&lt;BR /&gt;
Now with the new join query from the originating dataset, you can add a table, from the current project, and easily find "TOP50_COMMANDS" in the list.&lt;BR /&gt;
&lt;BR /&gt;
Hopefully you should be able to find the rest of your way from here.

Message was edited by: Chuck</description>
      <pubDate>Tue, 29 Jan 2008 20:27:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-running-total-in-EG/m-p/6644#M2109</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-01-29T20:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: Creating running total in EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-running-total-in-EG/m-p/6645#M2110</link>
      <description>Chuck,&lt;BR /&gt;
Thanks for the pointer. This will work only if I want 50 observations in total. What I am trying to do is to get top 50 observations for each value of X. If there are 5 distinct values of X I will have a total of 250 observations. Is there a way to accomplish this?&lt;BR /&gt;
Thanks</description>
      <pubDate>Tue, 29 Jan 2008 20:34:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-running-total-in-EG/m-p/6645#M2110</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-01-29T20:34:48Z</dc:date>
    </item>
    <item>
      <title>Re: Creating running total in EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-running-total-in-EG/m-p/6646#M2111</link>
      <description>Off the top of my head, what you are doing in code is the simplest and most elegant way.&lt;BR /&gt;
&lt;BR /&gt;
If you want to figure out a way with a Query dialog, you'll have to root around with the box, its options, calculated fields, etc. to see if you can figure out a way.&lt;BR /&gt;
&lt;BR /&gt;
There is a very complicated method that comes to mind; you query for the unique X values;  then, new queries, filtering for those explicit X values, resulting in your top 50's; then a final query that adds the resulting tables together.  But this is very ugly and painful.</description>
      <pubDate>Tue, 29 Jan 2008 20:47:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-running-total-in-EG/m-p/6646#M2111</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-01-29T20:47:34Z</dc:date>
    </item>
    <item>
      <title>Re: Creating running total in EG</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-running-total-in-EG/m-p/6647#M2112</link>
      <description>Here's another code-based way.  It's not as short and sweet, but it's versatile.  You just need to modify the top portion to set the macro variables to your data and column names.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
/* replace these values with your data/columns */&lt;BR /&gt;
%let data=SASHELP.PRDSALE;&lt;BR /&gt;
%let report=PRODUCT;&lt;BR /&gt;
%let measure=ACTUAL;&lt;BR /&gt;
%let measureformat=%str(format=DOLLAR12.2); /* to retain measure format in report */&lt;BR /&gt;
%let stat=SUM; /* or use MEAN, for average */&lt;BR /&gt;
%let n=50; /* max values to report per category */&lt;BR /&gt;
%let category=COUNTRY;&lt;BR /&gt;
title Top PRODUCTs based on ACTUAL Sales in each COUNTRY;&lt;BR /&gt;
footnote Generated on &amp;amp;SYSDATE;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
/* summarize the data across a category and store */&lt;BR /&gt;
/* the output in an output data set */&lt;BR /&gt;
proc means data=&amp;amp;data &amp;amp;stat noprint;&lt;BR /&gt;
	var &amp;amp;measure;&lt;BR /&gt;
	class &amp;amp;category &amp;amp;report;&lt;BR /&gt;
	output out=summary &amp;amp;stat=&amp;amp;measure &amp;amp;category /levels;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* store the value of the measure for ALL rows and &lt;BR /&gt;
/* the row count into a macro variable for use  */&lt;BR /&gt;
/* later in the report */&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
select &amp;amp;measure,_FREQ_ into :overall,:numobs&lt;BR /&gt;
from summary where _TYPE_=0;&lt;BR /&gt;
select count(distinct &amp;amp;category) into :categorycount from summary;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
/* sort the results so that we get the TOP values */&lt;BR /&gt;
/* rising to the top of the data set */&lt;BR /&gt;
proc sort data=work.summary out=work.topn;&lt;BR /&gt;
  where _type_&amp;gt;2;&lt;BR /&gt;
  by &amp;amp;category descending &amp;amp;measure;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* Pass through the data and output the first N */&lt;BR /&gt;
/* values for each category */&lt;BR /&gt;
data topn;&lt;BR /&gt;
  length rank 8;&lt;BR /&gt;
  label rank="Rank";&lt;BR /&gt;
  set topn;&lt;BR /&gt;
  by &amp;amp;category descending &amp;amp;measure;&lt;BR /&gt;
  if first.&amp;amp;category then rank=0;&lt;BR /&gt;
  rank+1;&lt;BR /&gt;
  if rank le &amp;amp;n then output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* Create a report listing for the top values in each category */&lt;BR /&gt;
footnote2 "&amp;amp;stat of &amp;amp;measure for ALL values of &amp;amp;report: &amp;amp;overall (&amp;amp;numobs total rows)";&lt;BR /&gt;
proc report data=topn;&lt;BR /&gt;
	columns &amp;amp;category rank &amp;amp;report &amp;amp;measure;&lt;BR /&gt;
	define &amp;amp;category /group;&lt;BR /&gt;
	define rank /display;&lt;BR /&gt;
	define &amp;amp;measure / analysis &amp;amp;measureformat;	&lt;BR /&gt;
run;&lt;BR /&gt;
quit; &lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Chris</description>
      <pubDate>Thu, 07 Feb 2008 15:00:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-running-total-in-EG/m-p/6647#M2112</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2008-02-07T15:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: Creating running total in EG (Top N)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-running-total-in-EG/m-p/6648#M2113</link>
      <description>Here is a more formal example for creating Top N reports in SAS and in SAS Enterprise Guide.  The example includes SAS programs, and also includes a custom task for EG so you can avoid the programming, if you want.&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/kb/33/009.html" target="_blank"&gt;http://support.sas.com/kb/33/009.html&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Chris</description>
      <pubDate>Fri, 29 Aug 2008 02:10:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-running-total-in-EG/m-p/6648#M2113</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2008-08-29T02:10:00Z</dc:date>
    </item>
    <item>
      <title>Re: Creating running total in EG (Top N)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-running-total-in-EG/m-p/6649#M2114</link>
      <description>Hi David&lt;BR /&gt;
Like you I'm an experienced coder and a bit resistive to use EG. So this was a nice challenge.&lt;BR /&gt;
&lt;BR /&gt;
What worked was righ clicking the SAS table in the project explorer window and then use „Filter and Query...“. I „pointed-and-clicked“ the following code:&lt;BR /&gt;
&lt;BR /&gt;
%_eg_conditional_dropds(WORK.Query_for_HAVE);&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL OUTOBS=50;&lt;BR /&gt;
 CREATE TABLE WORK.Query_for_HAVE AS SELECT HAVE.i,&lt;BR /&gt;
	 (COUNT(HAVE.i)) AS COUNT_OF_i &lt;BR /&gt;
 FROM WORK.HAVE AS HAVE&lt;BR /&gt;
 GROUP BY HAVE.i&lt;BR /&gt;
 ORDER BY COUNT_OF_i DESCENDING;&lt;BR /&gt;
QUIT;&lt;BR /&gt;
&lt;BR /&gt;
Regards&lt;BR /&gt;
Patrick</description>
      <pubDate>Fri, 29 Aug 2008 06:39:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-running-total-in-EG/m-p/6649#M2114</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2008-08-29T06:39:38Z</dc:date>
    </item>
  </channel>
</rss>

