<?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: Trying to get rid of error message regarding numeric datatype required to use division error. in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-get-rid-of-error-message-regarding-numeric-datatype/m-p/922226#M41374</link>
    <description>&lt;P&gt;You should use DIVIDE() function instead of '/' operator .&lt;/P&gt;
&lt;P&gt;Like:&lt;/P&gt;
&lt;P&gt;change&lt;/P&gt;
&lt;PRE&gt;'Variance'n / 'Month PY Actuals'n&lt;/PRE&gt;
&lt;P&gt;into&lt;/P&gt;
&lt;PRE&gt; divide(  'Variance'n , 'Month PY Actuals'n )&lt;/PRE&gt;</description>
    <pubDate>Fri, 29 Mar 2024 02:12:55 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2024-03-29T02:12:55Z</dc:date>
    <item>
      <title>Trying to get rid of error message regarding numeric datatype required to use division error.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-get-rid-of-error-message-regarding-numeric-datatype/m-p/922147#M41361</link>
      <description>&lt;P&gt;The data that I am using to divide says it is all numeric when I look at the table. When I try to divide two numeric values I get the error message 'ERROR: Expression using division (/) requires numeric types.' The first two create table blocks of code work and create a table with numeric data types. The third block gives me the error. I have copied the error log at the very bottom. Please let me know if you know how to solve this issue. I am working on SAS Citrix Workspace, not the SAS app in case that is relevant.&lt;/P&gt;&lt;PRE&gt;/*Create table to compare PY month actual expenses to current year*/
PROC SQL;
   CREATE TABLE WORK.PYActualsToCYActuals AS 
   SELECT t1.'GL account'n AS 'GL Account'n, 
   (MEAN(t1.Jan)) AS 'Month PY Actuals'n, 
   (SUM(t2.'Monthly Actuals'n)) As 'CY Actuals'n,

		((MEAN(t1.Jan)) - (SUM(t2.'Monthly Actuals'n))) AS Variance,
		((((MEAN(t1.Jan)) - (SUM(t2.'Monthly Actuals'n))))) AS 'Variance %'n

   FROM WORK.CLEAN_PY_YTD t1
   	FULL JOIN Work.Monthly_Actuals t2 ON (t1.'GL Account'n = t2.'G/L Account'n)
	WHERE (t1.Jan NE . AND t1.Jan NE 0 AND t1.'GL account'n NE 'Grand Total') 
	OR (t2.'Monthly Actuals'n NE . AND t2. 
	'Monthly Actuals'n NE 0 AND t1.'GL account'n NE 'Grand Total')

	GROUP BY t1.'GL Account'n;

Quit;

/*Change all . to 0s in the table*/
PROC SQL;
CREATE TABLE WORK.PYActualsToCYActuals AS
	SELECT 'GL Account'n,
		CASE WHEN ('Month PY Actuals'n = .) THEN ('Month PY Actuals'n = 0) 
		ELSE 'Month PY Actuals'n END AS 'Month PY Actuals'n,
		CASE WHEN ('CY Actuals'n = .) THEN ('CY Actuals'n = 0) 
		ELSE 'CY Actuals'n END AS 'CY Actuals'n,
		CASE WHEN ('CY Actuals'n = .) THEN ('CY Actuals'n = 0) 
		ELSE 'CY Actuals'n END AS 'CY Actuals'n,
		CASE WHEN ('Variance'n = .) THEN ('Variance'n = 0) 
		ELSE 'Variance'n END AS 'Variance'n,
		CASE WHEN ('Variance %'n = .) THEN ('Variance %'n = 0) 
		ELSE 'Variance %'n END AS 'Variance %'n
	FROM WORK.PYActualsToCYActuals;

QUIT;

/*Solve for variance as a percent*/
PROC SQL;
	CREATE TABLE WORK.PYActualsToCYActuals AS
	SELECT 'GL Account'n, 'Month PY Actuals'n, 'CY Actuals'n, 'Variance'n,
		CASE WHEN ('Month PY Actuals'n NE 0) AND ('CY Actuals'n NE 0)
			THEN ('Variance'n / 'Month PY Actuals'n) * 100
		WHEN 'CY Actuals'n NE 0
			THEN ('Variance'n / 'CY Actuals') * 100
		WHEN 'Month PY Actuals'n NE 0
			THEN ('Variance'n / 'Month PY Actuals'n) * 100
		ELSE 100 END AS 'Variance %'n

	FROM WORK.PYActualsToCYActuals;

Quit;


144        
145        /*Solve for variance as a percent*/
146        PROC SQL;
147        	CREATE TABLE WORK.PYActualsToCYActuals AS
148        	SELECT 'GL Account'n, 'Month PY Actuals'n, 'CY Actuals'n, 'Variance'n,
149        		CASE WHEN ('Month PY Actuals'n NE 0) AND ('CY Actuals'n NE 0)
150        			THEN ('Variance'n / 'Month PY Actuals'n) * 100
151        		WHEN 'CY Actuals'n NE 0
152        			THEN ('Variance'n / 'CY Actuals') * 100
153        		WHEN 'Month PY Actuals'n NE 0
154        			THEN ('Variance'n / 'Month PY Actuals'n) * 100
155        		ELSE 100 END AS 'Variance %'n
156        
157        	FROM WORK.PYActualsToCYActuals;
ERROR: Expression using division (/) requires numeric types.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
158        
159        Quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Mar 2024 17:02:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-get-rid-of-error-message-regarding-numeric-datatype/m-p/922147#M41361</guid>
      <dc:creator>CSB35</dc:creator>
      <dc:date>2024-03-28T17:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get rid of error message regarding numeric datatype required to use division error.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-get-rid-of-error-message-regarding-numeric-datatype/m-p/922150#M41363</link>
      <description>&lt;P&gt;What does "look at the table" mean? Print and screen views do not normally tell you the variable type.&lt;/P&gt;
&lt;P&gt;You need to look at the variable Properties, either Proc contents to get an output summary, click on the column heading in table viewer or if you use the SAS Explorer you can right click on a data set and select the View Columns to see the variable name, types labels and formats. Or use the Proc SQL describe table syntax.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tend to believe SAS when it reports something as not numeric. Either a variable is not numeric or something has snuck into your code that makes the expression get treated as not numeric by SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your Case statements are extremely lucky that you wanted to assign the value of 0 because in&lt;/P&gt;
&lt;PRE&gt;	CASE WHEN ('CY Actuals'n = .) THEN ('CY Actuals'n = 0) 
		ELSE 'CY Actuals'n END AS 'CY Actuals'n,&lt;/PRE&gt;
&lt;P&gt;The "then ('CY Actuals'n = 0)" bit of code is assigning the LOGICAL value of the comparison, which happens to be (. = 0) which is false and returns a number 0.&lt;/P&gt;
&lt;P&gt;better (and clearer for folks reading your code)&lt;/P&gt;
&lt;PRE&gt;	CASE WHEN ('CY Actuals'n = .) THEN 0 
		ELSE 'CY Actuals'n END AS 'CY Actuals'n,&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2024 17:27:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-get-rid-of-error-message-regarding-numeric-datatype/m-p/922150#M41363</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-03-28T17:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get rid of error message regarding numeric datatype required to use division error.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-get-rid-of-error-message-regarding-numeric-datatype/m-p/922152#M41365</link>
      <description>&lt;P&gt;My personal rule is that when SAS says something is not numeric, then it is not numeric, regardless of what the programmer says.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check the PROC CONTENTS output for data set work.pyactualstocyactuals&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2024 17:39:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-get-rid-of-error-message-regarding-numeric-datatype/m-p/922152#M41365</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-03-28T17:39:15Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get rid of error message regarding numeric datatype required to use division error.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-get-rid-of-error-message-regarding-numeric-datatype/m-p/922155#M41366</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/464621"&gt;@CSB35&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;151        		WHEN &lt;FONT color="#00DF00"&gt;'CY Actuals'n&lt;/FONT&gt; NE 0
152        			THEN ('Variance'n / &lt;FONT color="#FF0000"&gt;'CY Actuals'&lt;/FONT&gt;) * 100
&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The forgotten "&lt;FONT face="courier new,courier"&gt;n&lt;/FONT&gt;" turns the name literal of numeric variable&amp;nbsp;&lt;FONT face="courier new,courier"&gt;'CY Actuals'n&lt;/FONT&gt; into a character constant &lt;FONT face="courier new,courier"&gt;'CY Actuals'&lt;/FONT&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2024 17:54:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-get-rid-of-error-message-regarding-numeric-datatype/m-p/922155#M41366</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-03-28T17:54:58Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get rid of error message regarding numeric datatype required to use division error.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-get-rid-of-error-message-regarding-numeric-datatype/m-p/922157#M41367</link>
      <description>You are missing the "n" following one of the references to &lt;BR /&gt;&lt;BR /&gt;'CY_Actuals'</description>
      <pubDate>Thu, 28 Mar 2024 17:56:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-get-rid-of-error-message-regarding-numeric-datatype/m-p/922157#M41367</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2024-03-28T17:56:35Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get rid of error message regarding numeric datatype required to use division error.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-get-rid-of-error-message-regarding-numeric-datatype/m-p/922160#M41370</link>
      <description>&lt;P&gt;Why did you create variable names with spaces and other strange characters so that you are forced to use name literals to reference them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try changing the value of VALIDVARNAME option to V7 so that SAS will give you errors when you try to do that.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2024 18:20:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-get-rid-of-error-message-regarding-numeric-datatype/m-p/922160#M41370</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-03-28T18:20:22Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get rid of error message regarding numeric datatype required to use division error.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-get-rid-of-error-message-regarding-numeric-datatype/m-p/922226#M41374</link>
      <description>&lt;P&gt;You should use DIVIDE() function instead of '/' operator .&lt;/P&gt;
&lt;P&gt;Like:&lt;/P&gt;
&lt;P&gt;change&lt;/P&gt;
&lt;PRE&gt;'Variance'n / 'Month PY Actuals'n&lt;/PRE&gt;
&lt;P&gt;into&lt;/P&gt;
&lt;PRE&gt; divide(  'Variance'n , 'Month PY Actuals'n )&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Mar 2024 02:12:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-get-rid-of-error-message-regarding-numeric-datatype/m-p/922226#M41374</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-03-29T02:12:55Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get rid of error message regarding numeric datatype required to use division error.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-get-rid-of-error-message-regarding-numeric-datatype/m-p/922287#M41375</link>
      <description>&lt;P&gt;Thank you for the valuable information, especially on the Case statements! I did not know that and this will greatly improve my coding going forward.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regarding looking at the table, the create table blocks write over each other so that the end result is just one table (not sure if that is bad to do). If I only ran the code for the first two blocks it created a table showing the datatype as numeric, which was true, but I was missing an 'n'&amp;nbsp;by one of my variables caused it to be read as a string/creating the error.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Mar 2024 18:14:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-get-rid-of-error-message-regarding-numeric-datatype/m-p/922287#M41375</guid>
      <dc:creator>CSB35</dc:creator>
      <dc:date>2024-03-29T18:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get rid of error message regarding numeric datatype required to use division error.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-get-rid-of-error-message-regarding-numeric-datatype/m-p/922288#M41376</link>
      <description>&lt;P&gt;That is a good point. I am going to save that line for later haha. I was missing an n on one of my column header names causing it to be read as a string.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Mar 2024 18:17:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-get-rid-of-error-message-regarding-numeric-datatype/m-p/922288#M41376</guid>
      <dc:creator>CSB35</dc:creator>
      <dc:date>2024-03-29T18:17:17Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get rid of error message regarding numeric datatype required to use division error.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-get-rid-of-error-message-regarding-numeric-datatype/m-p/922289#M41377</link>
      <description>Thank you!</description>
      <pubDate>Fri, 29 Mar 2024 18:18:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-get-rid-of-error-message-regarding-numeric-datatype/m-p/922289#M41377</guid>
      <dc:creator>CSB35</dc:creator>
      <dc:date>2024-03-29T18:18:55Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get rid of error message regarding numeric datatype required to use division error.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-get-rid-of-error-message-regarding-numeric-datatype/m-p/922290#M41378</link>
      <description>Will try this! Thank you.</description>
      <pubDate>Fri, 29 Mar 2024 18:19:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-get-rid-of-error-message-regarding-numeric-datatype/m-p/922290#M41378</guid>
      <dc:creator>CSB35</dc:creator>
      <dc:date>2024-03-29T18:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to get rid of error message regarding numeric datatype required to use division error.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-get-rid-of-error-message-regarding-numeric-datatype/m-p/922291#M41379</link>
      <description>Thank you! Will use this going forward.</description>
      <pubDate>Fri, 29 Mar 2024 18:20:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-get-rid-of-error-message-regarding-numeric-datatype/m-p/922291#M41379</guid>
      <dc:creator>CSB35</dc:creator>
      <dc:date>2024-03-29T18:20:32Z</dc:date>
    </item>
  </channel>
</rss>

