<?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: adding a variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/adding-a-variable/m-p/17171#M3229</link>
    <description>It would be useful to see a data-sample the INPUT_DATA (columns/variables named) and the desired OUTPUT columns represented in your query/post reply.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
    <pubDate>Thu, 09 Apr 2009 20:37:34 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2009-04-09T20:37:34Z</dc:date>
    <item>
      <title>adding a variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/adding-a-variable/m-p/17170#M3228</link>
      <description>I have a variable called tot_ch which gives total charges.  which statement should I used to get the total number of tot_ch (total charges)by each site (site of facility that is charging).  I need to sum up all the charges (tot_ch) by site (site).&lt;BR /&gt;
&lt;BR /&gt;
thank you so much for your help.&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
RQ</description>
      <pubDate>Thu, 09 Apr 2009 20:00:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/adding-a-variable/m-p/17170#M3228</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-04-09T20:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: adding a variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/adding-a-variable/m-p/17171#M3229</link>
      <description>It would be useful to see a data-sample the INPUT_DATA (columns/variables named) and the desired OUTPUT columns represented in your query/post reply.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 09 Apr 2009 20:37:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/adding-a-variable/m-p/17171#M3229</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-04-09T20:37:34Z</dc:date>
    </item>
    <item>
      <title>Re: adding a variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/adding-a-variable/m-p/17172#M3230</link>
      <description>This may help.&lt;BR /&gt;
&lt;BR /&gt;
data abc;/*example dataset*/&lt;BR /&gt;
input site total_ch;&lt;BR /&gt;
datalines;&lt;BR /&gt;
&lt;BR /&gt;
1 5&lt;BR /&gt;
1 13&lt;BR /&gt;
1 12&lt;BR /&gt;
1 12&lt;BR /&gt;
2 34&lt;BR /&gt;
2 22&lt;BR /&gt;
2 44&lt;BR /&gt;
2 77&lt;BR /&gt;
3 12&lt;BR /&gt;
3 11&lt;BR /&gt;
3 12&lt;BR /&gt;
3 12&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
data xyz; set abc;&lt;BR /&gt;
by site;&lt;BR /&gt;
if first.site then count=0; count+1;&lt;BR /&gt;
if first.site then sum_total=total_ch; else sum_total+total_ch;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql; create table def as&lt;BR /&gt;
select site, count, max (sum_total) as maxtotal&lt;BR /&gt;
from xyz&lt;BR /&gt;
group by site&lt;BR /&gt;
having sum_total= calculated maxtotal;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
proc print data=def; run;&lt;BR /&gt;
&lt;BR /&gt;
This will give you the total counts (# of total charges) per site as well as the sum total charges by each site.</description>
      <pubDate>Thu, 09 Apr 2009 23:05:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/adding-a-variable/m-p/17172#M3230</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-04-09T23:05:59Z</dc:date>
    </item>
    <item>
      <title>Re: adding a variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/adding-a-variable/m-p/17173#M3231</link>
      <description>Hi:&lt;BR /&gt;
  Given this data, you can also use several different SAS procedures WITHOUT needing the DATA step or the PROC SQL step. Programs and output are below based on the ABC data. The doc describes how to make output data sets from any of these 3 procedures. Pick the one whose look and feel you like best. &lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
* Proc Report Program;&lt;BR /&gt;
               &lt;BR /&gt;
proc report data=abc nowd;&lt;BR /&gt;
  column site n total_ch total_ch=maxtot total_ch=mintot total_ch=avgtot;&lt;BR /&gt;
  define site / group;&lt;BR /&gt;
  define n / 'Count';&lt;BR /&gt;
  define total_ch/ sum "Sum Total";&lt;BR /&gt;
  define maxtot / max "Max Total";&lt;BR /&gt;
  define mintot / min "Min Total";&lt;BR /&gt;
  define avgtot / mean "Avg Total";&lt;BR /&gt;
run;&lt;BR /&gt;
                        &lt;BR /&gt;
******Proc Report Output******&lt;BR /&gt;
       site      Count  Sum Total  Max Total  Min Total  Avg Total&lt;BR /&gt;
          1          4         42         13          5       10.5&lt;BR /&gt;
          2          4        177         77         22      44.25&lt;BR /&gt;
          3          4         47         12         11      11.75&lt;BR /&gt;
&lt;BR /&gt;
                                    &lt;BR /&gt;
** Proc Means Program;&lt;BR /&gt;
proc means data=abc n sum max min mean;&lt;BR /&gt;
  class site;&lt;BR /&gt;
  var total_ch;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
                                           &lt;BR /&gt;
*******Proc Means Output******&lt;BR /&gt;
The MEANS Procedure&lt;BR /&gt;
                &lt;BR /&gt;
                              Analysis Variable : total_ch&lt;BR /&gt;
                                             &lt;BR /&gt;
                  N&lt;BR /&gt;
        site    Obs     N             Sum         Maximum         Minimum            Mean&lt;BR /&gt;
-----------------------------------------------------------------------------------------&lt;BR /&gt;
           1      4     4      42.0000000      13.0000000       5.0000000      10.5000000&lt;BR /&gt;
&lt;BR /&gt;
           2      4     4     177.0000000      77.0000000      22.0000000      44.2500000&lt;BR /&gt;
&lt;BR /&gt;
           3      4     4      47.0000000      12.0000000      11.0000000      11.7500000&lt;BR /&gt;
-----------------------------------------------------------------------------------------&lt;BR /&gt;
                                         &lt;BR /&gt;
                                        &lt;BR /&gt;
*Proc Tabulate Program;&lt;BR /&gt;
proc tabulate data=abc;&lt;BR /&gt;
  class site;&lt;BR /&gt;
  var total_ch;&lt;BR /&gt;
  table site,&lt;BR /&gt;
        total_ch*(n sum max min mean);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
                 &lt;BR /&gt;
****** Proc Tabulate Output******&lt;BR /&gt;
                               &lt;BR /&gt;
+-------------------------------------------+&lt;BR /&gt;
|        |             total_ch             |&lt;BR /&gt;
|        +----------------------------------+&lt;BR /&gt;
|        |  N   | Sum  | Max  | Min  | Mean |&lt;BR /&gt;
+--------+------+------+------+------+------+&lt;BR /&gt;
|site    |      |      |      |      |      |&lt;BR /&gt;
+--------+      |      |      |      |      |&lt;BR /&gt;
|1       |  4.00| 42.00| 13.00|  5.00| 10.50|&lt;BR /&gt;
+--------+------+------+------+------+------+&lt;BR /&gt;
|2       |  4.00|177.00| 77.00| 22.00| 44.25|&lt;BR /&gt;
+--------+------+------+------+------+------+&lt;BR /&gt;
|3       |  4.00| 47.00| 12.00| 11.00| 11.75|&lt;BR /&gt;
+-------------------------------------------+&lt;BR /&gt;
                            &lt;BR /&gt;
&lt;BR /&gt;
[/pre]</description>
      <pubDate>Fri, 10 Apr 2009 01:49:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/adding-a-variable/m-p/17173#M3231</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-04-10T01:49:13Z</dc:date>
    </item>
    <item>
      <title>Re: adding a variable - program worked!</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/adding-a-variable/m-p/17174#M3232</link>
      <description>Thank you very much for your help.  It worked and I think that by using any of the programs created it would work.&lt;BR /&gt;
&lt;BR /&gt;
Thanks again!</description>
      <pubDate>Mon, 13 Apr 2009 16:43:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/adding-a-variable/m-p/17174#M3232</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-04-13T16:43:21Z</dc:date>
    </item>
  </channel>
</rss>

