<?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: how to create variable in sql? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-variable-in-sql/m-p/484092#M125615</link>
    <description>&lt;P&gt;You can create only one table per SQL query so it is going to take 3 SQL queries to get what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IMO this is a dumb homework question, as a DATA step is the best method for doing BY-type processing and creating multiple tables in the one step.&lt;/P&gt;</description>
    <pubDate>Sun, 05 Aug 2018 02:46:16 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2018-08-05T02:46:16Z</dc:date>
    <item>
      <title>how to create variable in sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-variable-in-sql/m-p/484079#M125611</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data discountRet_kinson2 discountCat_kinson2 discountInt_kinson2;
   set work.orders;
   by Customer_ID Order_Type;
   if first.Order_Type then Total_Sales=0;
   Total_Sales+Total_Retail_Price;
   if last.Order_Type and Total_Sales &amp;gt;= 200 then do;
      select (Order_Type);
         when (1) output discountRet_kinson2;
	     when (2) output discountCat_kinson2;
	     when (3) output discountInt_kinson2;
	  end;
   end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have the above code and I have to express them using SQL instead of data step.&lt;/P&gt;&lt;P&gt;I have try a few lines of code, but I don't know how to express the if subset statement in SQL.&lt;/P&gt;&lt;P&gt;Is there any similar procedure in SQL that I ignored?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create table work.discountRet_sliu116 
                work.discountCat_sliu116
                work.discountInt_sliu116 as
   select Customer_ID, Customer_Name, Total_Sales
   from hw7.orders2018&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 Aug 2018 01:18:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-variable-in-sql/m-p/484079#M125611</guid>
      <dc:creator>233</dc:creator>
      <dc:date>2018-08-05T01:18:14Z</dc:date>
    </item>
    <item>
      <title>Re: how to create variable in sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-variable-in-sql/m-p/484081#M125612</link>
      <description>&lt;P&gt;SQL has no notion of row order. Why must you use SQL?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 01:50:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-variable-in-sql/m-p/484081#M125612</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-08-05T01:50:11Z</dc:date>
    </item>
    <item>
      <title>Re: how to create variable in sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-variable-in-sql/m-p/484084#M125613</link>
      <description>&lt;P&gt;My homework requires me to do that.&lt;/P&gt;&lt;P&gt;I think I didn't make enough clarification. In the data step, a if subset statement is using to create a variable called total_sales (seems like&amp;nbsp;accumulate the value of a original variable called retail_price)&lt;/P&gt;&lt;P&gt;And now I have to code them using SQL, so I was wondering is there anyway I could do in SQL to create a variable and assign the accumulation of the values from the existed variable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 01:57:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-variable-in-sql/m-p/484084#M125613</guid>
      <dc:creator>233</dc:creator>
      <dc:date>2018-08-05T01:57:01Z</dc:date>
    </item>
    <item>
      <title>Re: how to create variable in sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-variable-in-sql/m-p/484092#M125615</link>
      <description>&lt;P&gt;You can create only one table per SQL query so it is going to take 3 SQL queries to get what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IMO this is a dumb homework question, as a DATA step is the best method for doing BY-type processing and creating multiple tables in the one step.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 02:46:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-variable-in-sql/m-p/484092#M125615</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2018-08-05T02:46:16Z</dc:date>
    </item>
    <item>
      <title>Re: how to create variable in sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-variable-in-sql/m-p/484094#M125616</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table work.discountRet_sliu116 as
  select  Customer_ID
         ,Customer_Name
         ,sum(Total_Retail_Price) as Total_Sales
  from hw7.orders2018
  where Order_type = 1
  group by  Customer_ID
           ,Customer_Name
  having sum(Total_Retail_Price) &amp;gt;= 200
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Something like the above should work for one order type, then just repeat for the other two.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 02:57:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-variable-in-sql/m-p/484094#M125616</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2018-08-05T02:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: how to create variable in sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-variable-in-sql/m-p/484097#M125617</link>
      <description>&lt;P&gt;Thank you so much! I am not very familiar with SQL and I am looking for notes of sub query but still stuck on the problem. Really appreciate your help!&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 03:05:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-variable-in-sql/m-p/484097#M125617</guid>
      <dc:creator>233</dc:creator>
      <dc:date>2018-08-05T03:05:51Z</dc:date>
    </item>
    <item>
      <title>Re: how to create variable in sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-variable-in-sql/m-p/484100#M125619</link>
      <description>&lt;P&gt;No problem. I don't think you need sub-queries in this case, not unless there is more to the problem than you have posted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All I'm using is a GROUP BY to summarise the data by customer ID.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 03:25:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-variable-in-sql/m-p/484100#M125619</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2018-08-05T03:25:44Z</dc:date>
    </item>
  </channel>
</rss>

