<?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: sum function for charecter data type in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/sum-function-for-charecter-data-type/m-p/71675#M20701</link>
    <description>Your code should either be &lt;BR /&gt;
&lt;BR /&gt;
PROC SQL;&lt;BR /&gt;
&lt;B&gt;Connect to oracle.....&lt;/B&gt;&lt;BR /&gt;
create table WORK.xx as &lt;B&gt;select * from connection to oracle (&lt;/B&gt;&lt;BR /&gt;
SELECT "xyz" as File_name, &lt;BR /&gt;
Count(*) AS members, &lt;BR /&gt;
sum(yy_AMT) as yy_AMT&lt;BR /&gt;
FROM WORK.zzz&lt;BR /&gt;
&lt;B&gt;)&lt;/B&gt;; &lt;BR /&gt;
quit; &lt;BR /&gt;
&lt;BR /&gt;
or &lt;BR /&gt;
&lt;BR /&gt;
PROC SQL;&lt;BR /&gt;
create table WORK.xx as &lt;BR /&gt;
 SELECT "xyz" as File_name, &lt;BR /&gt;
Count(*) AS members, &lt;BR /&gt;
sum(yy_AMT) as yy_AMT&lt;BR /&gt;
FROM WORK.zzz&lt;BR /&gt;
; &lt;BR /&gt;
quit; &lt;BR /&gt;
&lt;BR /&gt;
The ANSI part of the syntax is the same, but there can be differences on "extensions" like sas dataset options or oracle partitions.&lt;BR /&gt;
&lt;BR /&gt;
In the 1st case you must use oracle syntax (and functions like to_number()) inside the connection brackets. You must use sas syntax outside (where the select * is).&lt;BR /&gt;
&lt;BR /&gt;
In the 2nd case you must use sas syntax (and functions like input() that Scott suggested). This works:&lt;BR /&gt;
&lt;BR /&gt;
data T;&lt;BR /&gt;
  X='1';output;&lt;BR /&gt;
  X='2';output;&lt;BR /&gt;
proc sql; &lt;BR /&gt;
  select sum(input(X,1.)) from T;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
This works too:&lt;BR /&gt;
&lt;BR /&gt;
proc sql; &lt;BR /&gt;
connect to ORACLE ...&lt;BR /&gt;
select * from connection to oracle (&lt;BR /&gt;
  select sum(to_number(APPLNT_LOCL_ID)) from ... where ROWNUM ≤ 10);&lt;BR /&gt;
disconnect from oracle;	&lt;BR /&gt;
quit;</description>
    <pubDate>Thu, 17 Sep 2009 00:35:38 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2009-09-17T00:35:38Z</dc:date>
    <item>
      <title>sum function for charecter data type</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sum-function-for-charecter-data-type/m-p/71671#M20697</link>
      <description>I need to apply sum function to a character data type from a sas data set using PROC SQL. I am trying to use cast and to_number but gives me a error message "needs a numeric argument for sum function&lt;BR /&gt;
the code is something like this.&lt;BR /&gt;
PROC SQL;&lt;BR /&gt;
Connect to oracle.....&lt;BR /&gt;
create table WORK.xx as&lt;BR /&gt;
(	SELECT "xyz" as File_name, &lt;BR /&gt;
	Count(*) AS members, &lt;BR /&gt;
	sum(yy_AMT) as yy_AMT&lt;BR /&gt;
	FROM WORK.zzz&lt;BR /&gt;
);  &lt;BR /&gt;
quit; &lt;BR /&gt;
where yy_amt was defined as charecter data type in work.zzz dataset.</description>
      <pubDate>Tue, 15 Sep 2009 18:45:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sum-function-for-charecter-data-type/m-p/71671#M20697</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-09-15T18:45:41Z</dc:date>
    </item>
    <item>
      <title>Re: sum function for charecter data type</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sum-function-for-charecter-data-type/m-p/71672#M20698</link>
      <description>Look at using the INPUT function when selecting the variable yy_AMT inside the SUM(  ) function specification.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Tue, 15 Sep 2009 18:52:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sum-function-for-charecter-data-type/m-p/71672#M20698</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-09-15T18:52:33Z</dc:date>
    </item>
    <item>
      <title>Re: sum function for charecter data type</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sum-function-for-charecter-data-type/m-p/71673#M20699</link>
      <description>You connect to oracle, but don't use the connection?&lt;BR /&gt;
In other words, is the SQL following oracle's syntax or sas'?</description>
      <pubDate>Wed, 16 Sep 2009 01:42:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sum-function-for-charecter-data-type/m-p/71673#M20699</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2009-09-16T01:42:47Z</dc:date>
    </item>
    <item>
      <title>Re: sum function for charecter data type</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sum-function-for-charecter-data-type/m-p/71674#M20700</link>
      <description>Chris,&lt;BR /&gt;
I did not understand your question. But from what I understood. Yes I am using PROC SQL and connecting to oracle and the select statement is in the SQL syntax.What did you mean by your question? What are you trying to hint?Let me know. So, that I can think on the correct lines.</description>
      <pubDate>Wed, 16 Sep 2009 14:52:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sum-function-for-charecter-data-type/m-p/71674#M20700</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-09-16T14:52:19Z</dc:date>
    </item>
    <item>
      <title>Re: sum function for charecter data type</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sum-function-for-charecter-data-type/m-p/71675#M20701</link>
      <description>Your code should either be &lt;BR /&gt;
&lt;BR /&gt;
PROC SQL;&lt;BR /&gt;
&lt;B&gt;Connect to oracle.....&lt;/B&gt;&lt;BR /&gt;
create table WORK.xx as &lt;B&gt;select * from connection to oracle (&lt;/B&gt;&lt;BR /&gt;
SELECT "xyz" as File_name, &lt;BR /&gt;
Count(*) AS members, &lt;BR /&gt;
sum(yy_AMT) as yy_AMT&lt;BR /&gt;
FROM WORK.zzz&lt;BR /&gt;
&lt;B&gt;)&lt;/B&gt;; &lt;BR /&gt;
quit; &lt;BR /&gt;
&lt;BR /&gt;
or &lt;BR /&gt;
&lt;BR /&gt;
PROC SQL;&lt;BR /&gt;
create table WORK.xx as &lt;BR /&gt;
 SELECT "xyz" as File_name, &lt;BR /&gt;
Count(*) AS members, &lt;BR /&gt;
sum(yy_AMT) as yy_AMT&lt;BR /&gt;
FROM WORK.zzz&lt;BR /&gt;
; &lt;BR /&gt;
quit; &lt;BR /&gt;
&lt;BR /&gt;
The ANSI part of the syntax is the same, but there can be differences on "extensions" like sas dataset options or oracle partitions.&lt;BR /&gt;
&lt;BR /&gt;
In the 1st case you must use oracle syntax (and functions like to_number()) inside the connection brackets. You must use sas syntax outside (where the select * is).&lt;BR /&gt;
&lt;BR /&gt;
In the 2nd case you must use sas syntax (and functions like input() that Scott suggested). This works:&lt;BR /&gt;
&lt;BR /&gt;
data T;&lt;BR /&gt;
  X='1';output;&lt;BR /&gt;
  X='2';output;&lt;BR /&gt;
proc sql; &lt;BR /&gt;
  select sum(input(X,1.)) from T;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
This works too:&lt;BR /&gt;
&lt;BR /&gt;
proc sql; &lt;BR /&gt;
connect to ORACLE ...&lt;BR /&gt;
select * from connection to oracle (&lt;BR /&gt;
  select sum(to_number(APPLNT_LOCL_ID)) from ... where ROWNUM ≤ 10);&lt;BR /&gt;
disconnect from oracle;	&lt;BR /&gt;
quit;</description>
      <pubDate>Thu, 17 Sep 2009 00:35:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sum-function-for-charecter-data-type/m-p/71675#M20701</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2009-09-17T00:35:38Z</dc:date>
    </item>
  </channel>
</rss>

