<?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: SQL adding variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/346475#M273024</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It worked. What you posted is what I was trying to do all along. For some reason it's not letting me provide the data table, not sure why.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for your help&lt;/P&gt;</description>
    <pubDate>Sun, 02 Apr 2017 04:02:22 GMT</pubDate>
    <dc:creator>Scott86</dc:creator>
    <dc:date>2017-04-02T04:02:22Z</dc:date>
    <item>
      <title>SQL adding variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/344362#M273010</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I cannot get this code to work and I cannot figure out why (the code should explain what I'm trying to achieve), Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;title "Countries";&lt;BR /&gt;PROC SQL;&lt;BR /&gt;SELECT distinct country,&lt;BR /&gt;Customer_Firstname, Customer_lastname, Customer_ID, Street_ID / (Customer_ID * Customer_type_ID) as House_price&lt;BR /&gt;format = dollar15.2,&lt;BR /&gt;house_price * 0.03 as rates&lt;BR /&gt;format = dollar12.2,&lt;BR /&gt;input(rates, dollar12.2),&lt;BR /&gt;sum(rates) as total&lt;BR /&gt;format = dollar12.2,&lt;BR /&gt;CONCAT(customer_firstname,' ',customer_lastname) as Cust_Name,&lt;BR /&gt;count(distinct customer_ID) as total_customer_base,&lt;BR /&gt;rates / total_customer_base as Avg_rates&lt;BR /&gt;format = dollar12.2&lt;BR /&gt;FROM scott.customer&lt;BR /&gt;where rates &amp;gt; Avg_rates&lt;BR /&gt;order by rates desc;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;title;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My error log is below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: The SUM summary function requires a numeric argument.&lt;BR /&gt;ERROR: Function CONCAT could not be located.&lt;BR /&gt;ERROR: The following columns were not found in the contributing tables: Avg_rates, house_price,&lt;BR /&gt;rates, total_customer_base.&lt;BR /&gt;274 quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2017 01:54:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/344362#M273010</guid>
      <dc:creator>Scott86</dc:creator>
      <dc:date>2017-03-26T01:54:42Z</dc:date>
    </item>
    <item>
      <title>Re: SQL adding variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/344364#M273011</link>
      <description>&lt;P&gt;The rate variable should be numeric, its character. Combine the previous variable in the SUM ()&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CONCAT, as noted, is note a SAS function. CATT, CATX are probably what you want.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lastly, your table customer doesn't seem to have the variables you think it does. Run a proc contents to confirm variable names and types.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/135820"&gt;@Scott86&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I cannot get this code to work and I cannot figure out why (the code should explain what I'm trying to achieve), Any help would be appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;title "Countries";&lt;BR /&gt;PROC SQL;&lt;BR /&gt;SELECT distinct country,&lt;BR /&gt;Customer_Firstname, Customer_lastname, Customer_ID, Street_ID / (Customer_ID * Customer_type_ID) as House_price&lt;BR /&gt;format = dollar15.2,&lt;BR /&gt;house_price * 0.03 as rates&lt;BR /&gt;format = dollar12.2,&lt;BR /&gt;input(rates, dollar12.2),&lt;BR /&gt;sum(rates) as total&lt;BR /&gt;format = dollar12.2,&lt;BR /&gt;CONCAT(customer_firstname,' ',customer_lastname) as Cust_Name,&lt;BR /&gt;count(distinct customer_ID) as total_customer_base,&lt;BR /&gt;rates / total_customer_base as Avg_rates&lt;BR /&gt;format = dollar12.2&lt;BR /&gt;FROM scott.customer&lt;BR /&gt;where rates &amp;gt; Avg_rates&lt;BR /&gt;order by rates desc;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;title;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My error log is below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: The SUM summary function requires a numeric argument.&lt;BR /&gt;ERROR: Function CONCAT could not be located.&lt;BR /&gt;ERROR: The following columns were not found in the contributing tables: Avg_rates, house_price,&lt;BR /&gt;rates, total_customer_base.&lt;BR /&gt;274 quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2017 02:21:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/344364#M273011</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-26T02:21:15Z</dc:date>
    </item>
    <item>
      <title>Re: SQL adding variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/344370#M273012</link>
      <description>&lt;P&gt;The following lines of your code jumped out at me:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;input(rates, dollar12.2),
sum(rates) as total
format = dollar12.2,
CONCAT&lt;/PRE&gt;
&lt;P&gt;You had just calculated rates in the lines before that code. Remove the first line (i.e.)&lt;/P&gt;
&lt;PRE&gt;input(rates, dollar12.2),&lt;/PRE&gt;
&lt;P&gt;Then, like &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;said, CONCAT&amp;nbsp;isn't a SAS function. You want:&lt;/P&gt;
&lt;PRE&gt;CATX(' ',customer_firstname,customer_lastname) as Cust_Name,&lt;/PRE&gt;
&lt;P&gt;Finally, where you are using calculated variables after they're created, you may have to preface their names with the word:&lt;/P&gt;
&lt;P&gt;calculated (e.g., calculated rates)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2017 03:16:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/344370#M273012</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-26T03:16:37Z</dc:date>
    </item>
    <item>
      <title>Re: SQL adding variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/344375#M273013</link>
      <description>&lt;P&gt;How do I make rates numeric? I thought by setting the format as dollar12.2 it would make it numeric. Also the variables that are not in the table are ones I'm trying to calculate.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2017 03:58:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/344375#M273013</guid>
      <dc:creator>Scott86</dc:creator>
      <dc:date>2017-03-26T03:58:04Z</dc:date>
    </item>
    <item>
      <title>Re: SQL adding variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/344377#M273014</link>
      <description>&lt;P&gt;The message says that dataset&amp;nbsp;&lt;SPAN&gt;scott.customer does not contain variables&amp;nbsp;Avg_rates, house_price,&lt;BR /&gt;rates, total_customer_base.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2017 04:15:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/344377#M273014</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-03-26T04:15:07Z</dc:date>
    </item>
    <item>
      <title>Re: SQL adding variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/344471#M273015</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/135820"&gt;@Scott86&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe I understand what you're trying to achieve but there are quite a few things wrong with your code. The fastest way to answer your question would be to post working and tested code.&amp;nbsp;Please post sample data (a SAS data step creating such sample data).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What you've got wrong in your code is mostly about "timing". You're assuming that you can create a new variable in a SELECT clause and then use this new variable straight away in the same select clause. Well: That's with standard SQL not the case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having said that: The SAS SQL flavour provides a keyword &lt;SPAN&gt;CALCULATED &lt;/SPAN&gt;which allows you to reference a calculated column in the same SQL SELECT clause. &lt;A href="http://support.sas.com/documentation/cdl/en/sqlproc/69822/HTML/default/viewer.htm#n0jxri3yohqdwbn1slekmsc882gz.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/sqlproc/69822/HTML/default/viewer.htm#n0jxri3yohqdwbn1slekmsc882gz.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're not dealing with large data volumes then it's sometimes also easier to implement and read if you're not trying to do everything in a single SQL but if you split it up into several steps. You could implement a first SQL to just create the calculated columns and then a 2nd SQL where you use these calculated columns (and there are then also ways to combine these two SQL's into one using a inline view which then is proper SQL syntax and doesn't need the CALCULATED keyword anymore.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Provide some sample data and we can show you working code options for what you're trying to achieve.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2017 23:46:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/344471#M273015</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-03-26T23:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: SQL adding variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/344489#M273016</link>
      <description>&lt;P&gt;I can't see proper SQL code. please can you give a dataset and let us know what exactly you are looking.&lt;/P&gt;&lt;P&gt;As &amp;nbsp;I can see some mistakes:&lt;/P&gt;&lt;P&gt;Customer_ID, Street_ID / (Customer_ID * Customer_type_ID) as House_price : how the possibility to calculate ID for house_price.&lt;/P&gt;&lt;P&gt;sum(rates) as total : You can use total in the same sql as by using calculated total&lt;/P&gt;&lt;P&gt;CONCAT(customer_firstname,' ',customer_lastname) as Cust_Name : No Concat in SAS as previous authors mentioned&lt;/P&gt;&lt;P&gt;count(distinct customer_ID) as total_customer_base : You have to take as another sql statement.&lt;/P&gt;&lt;P&gt;Please give a sample dataset and what exactly you want?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 02:02:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/344489#M273016</guid>
      <dc:creator>lakshmi_74</dc:creator>
      <dc:date>2017-03-27T02:02:29Z</dc:date>
    </item>
    <item>
      <title>Re: SQL adding variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/344497#M273017</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;title "Countries";&lt;BR /&gt;PROC SQL;&lt;BR /&gt;SELECT distinct country,&lt;BR /&gt;Customer_Firstname, Customer_lastname, Customer_ID, Street_ID / (Customer_ID * Customer_type_ID) as House_price&lt;BR /&gt;format = dollar15.2,&lt;BR /&gt;calculated house_price * 0.03 as rates&lt;BR /&gt;format = dollar12.2,&lt;BR /&gt;sum(calculated rates) as total&lt;BR /&gt;format = dollar12.2,&lt;BR /&gt;Catx(' ',customer_lastname,customer_firstname) as Cust_Name,&lt;BR /&gt;count(distinct customer_ID) as total_customer_base,&lt;BR /&gt;calculated rates / calculated total_customer_base as Avg_rates&lt;BR /&gt;format = dollar12.2&lt;BR /&gt;FROM scott.customer&lt;BR /&gt;where calculated rates &amp;gt; calculated Avg_rates&lt;BR /&gt;order by rates desc;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;title;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This code gives me this error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Summary functions are restricted to the SELECT and HAVING clauses only.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also it won't let me attach a SAS data table, do I have to copy paste it to excel?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 03:32:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/344497#M273017</guid>
      <dc:creator>Scott86</dc:creator>
      <dc:date>2017-03-27T03:32:50Z</dc:date>
    </item>
    <item>
      <title>Re: SQL adding variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/344519#M273018</link>
      <description>&lt;P&gt;Can you give us info. what exactly you want to get the results? As sometimes in SQL you have to use subqueries according to your criteria.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 06:44:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/344519#M273018</guid>
      <dc:creator>lakshmi_74</dc:creator>
      <dc:date>2017-03-27T06:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: SQL adding variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/344535#M273019</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/135820"&gt;@Scott86&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;We really need sample data to support you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Attaching a SAS file should be possible but it's not a good thing for us as such SAS files are SAS version and OS specific. It's much better if you post SAS data step code which generates sample data.&lt;/P&gt;
&lt;P&gt;Most people don't like Excel file attachments for security reasons.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a simple and easy to use way how you can create&amp;nbsp;such data step code using your SAS file (SAS table) as input.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;How to create a data step version of your data AKA generate sample data for forums&lt;/STRONG&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Lib&lt;WBR /&gt;rary/How-to-create-a-data-step-version-of-your-dat&lt;WBR /&gt;...&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 07:55:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/344535#M273019</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-03-27T07:55:07Z</dc:date>
    </item>
    <item>
      <title>Re: SQL adding variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/346442#M273020</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to break down the steps now.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data customer1;&lt;BR /&gt;set scott.customer;&lt;BR /&gt;House_price = sum(Street_ID)/ (sum(Customer_ID) * sum(Customer_type_ID));&lt;BR /&gt;format House_price = dollar12.2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a new error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;18 data customer1;&lt;BR /&gt;19 set scott.customer;&lt;BR /&gt;20 House_price = sum(Street_ID)/ (sum(Customer_ID) * sum(Customer_type_ID));&lt;BR /&gt;21 format House_price = dollar12.2;&lt;BR /&gt;-&lt;BR /&gt;79&lt;BR /&gt;ERROR 79-322: Expecting a DEFAULT.&lt;/P&gt;&lt;P&gt;22 run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I try attach the data set it give me this error: '&lt;SPAN&gt;The contents of the attachment doesn't match its file type.'&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Apr 2017 22:56:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/346442#M273020</guid>
      <dc:creator>Scott86</dc:creator>
      <dc:date>2017-04-01T22:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: SQL adding variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/346444#M273021</link>
      <description>&lt;P&gt;I doubt the SUM function is doing what you think it does. Check your parentheses on previous line, house_price calculation. You have too many.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Apr 2017 23:01:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/346444#M273021</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-01T23:01:40Z</dc:date>
    </item>
    <item>
      <title>Re: SQL adding variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/346445#M273022</link>
      <description>&lt;P&gt;Re attachment, what file type are you trying to attach?&lt;/P&gt;</description>
      <pubDate>Sat, 01 Apr 2017 23:03:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/346445#M273022</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-01T23:03:56Z</dc:date>
    </item>
    <item>
      <title>Re: SQL adding variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/346452#M273023</link>
      <description>&lt;P&gt;Use the CODE icons in the web form so that you formatting doesn't disappear. &amp;nbsp;Here is original SELECT statement re-formatted to make it easier to read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SELECT distinct
  country
, Customer_Firstname
, Customer_lastname
, Customer_ID
, Street_ID / (Customer_ID * Customer_type_ID) as House_price format = dollar15.2
, house_price * 0.03 as rates format = dollar12.2
, input(rates, dollar12.2)
, sum(rates) as total format = dollar12.2
, CONCAT(customer_firstname,' ',customer_lastname) as Cust_Name
, count(distinct customer_ID) as total_customer_base
, rates / total_customer_base as Avg_rates format = dollar12.2
  FROM scott.customer
  where rates &amp;gt; Avg_rates
  order by rates desc
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So let's look and see what this is doing. &amp;nbsp;The first three variables are straight copies of existing variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The fourth variable you are deriving as&amp;nbsp;&lt;STRONG&gt;House_price.&lt;/STRONG&gt;&amp;nbsp;Note that this will work only if the three variables used are numbers.&lt;/P&gt;
&lt;P&gt;For the fifth variable you are trying to reference this new variable House_price. &amp;nbsp;To do that you need to add the keyword CALCULATED.&lt;/P&gt;
&lt;P&gt;For the sixth variable&amp;nbsp;you are indicating that the variable RATES exists on the input and is a character variable. Also you are not giving this new variable a name.&lt;/P&gt;
&lt;P&gt;For the 7th variable you appear to be trying to use the aggregate function SUM() on the same variable RATES that you just assumed above was a character string. &amp;nbsp;So which is it? &amp;nbsp;is RATES a number or a character string?&lt;/P&gt;
&lt;P&gt;For the 8th you reference an unknow function CONCAT().&lt;/P&gt;
&lt;P&gt;For the 9th you again are referencing an aggregate function COUNT().&lt;/P&gt;
&lt;P&gt;For the 10th you are again referencing the problematic RATES variable of unknown type and unknown origin and you are also referencing the new variable total_cutomer_base without using the CALCULATED keyword.&lt;/P&gt;
&lt;P&gt;So here is an attempt to clean it up a littile, but without a description of the vairables in your source table and a verbal description of how you want it transformed we cannot really help you much.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SELECT distinct
  country
, Customer_Firstname
, Customer_lastname
, Customer_ID
, Street_ID / (Customer_ID * Customer_type_ID) as House_price format = dollar15.2
, (calculated house_price) * 0.03 as rates format = dollar12.2
, sum( calculated rates) as total format = dollar12.2
, CATX(' ',customer_firstname,customer_lastname) as Cust_Name
, count(distinct customer_ID) as total_customer_base
, calculated rates / calculated total_customer_base as Avg_rates format = dollar12.2
  FROM scott.customer
  having calculated rates &amp;gt; calculated Avg_rates
  order by calculated rates desc
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 02 Apr 2017 00:24:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/346452#M273023</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-04-02T00:24:35Z</dc:date>
    </item>
    <item>
      <title>Re: SQL adding variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/346475#M273024</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It worked. What you posted is what I was trying to do all along. For some reason it's not letting me provide the data table, not sure why.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for your help&lt;/P&gt;</description>
      <pubDate>Sun, 02 Apr 2017 04:02:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-adding-variables/m-p/346475#M273024</guid>
      <dc:creator>Scott86</dc:creator>
      <dc:date>2017-04-02T04:02:22Z</dc:date>
    </item>
  </channel>
</rss>

