<?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 Do loop within PROC SQL in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Do-loop-within-PROC-SQL/m-p/358267#M64314</link>
    <description>&lt;P&gt;What I would like is to have a do loop within PROC SQL instead of doing it in two steps with PROC SQL and then Data Step:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
	CREATE TABLE TEST AS 
    SELECT Quantity,
	       Price,
           sum(DEC) AS total_DEC,
	       sum(Ingredient_Cost) AS total_ing_cost,
		   (Calculated total_DEC-Calculated total_ing_cost)/ Calculated total_DEC AS discount,
           (Calculated total_DEC*(1-.82)) format=8.2 AS target_ing_cost,
           (Calculated total_DEC-Calculated target_ing_cost)/ Calculated total_DEC AS target_discount  
      FROM EGTASK.DATA_EXAMPLE;
QUIT;

data TEST_2;
  set TEST;
  do i=.8 to 1.2 by .01;
    target_cost = Price*Quantity*i;
	output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want is to accomplish what is being done in the data step in the PROC SQL instead (do it in one step). Is this possible?&lt;/P&gt;</description>
    <pubDate>Fri, 12 May 2017 15:44:58 GMT</pubDate>
    <dc:creator>JediApprentice</dc:creator>
    <dc:date>2017-05-12T15:44:58Z</dc:date>
    <item>
      <title>Do loop within PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-loop-within-PROC-SQL/m-p/358267#M64314</link>
      <description>&lt;P&gt;What I would like is to have a do loop within PROC SQL instead of doing it in two steps with PROC SQL and then Data Step:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
	CREATE TABLE TEST AS 
    SELECT Quantity,
	       Price,
           sum(DEC) AS total_DEC,
	       sum(Ingredient_Cost) AS total_ing_cost,
		   (Calculated total_DEC-Calculated total_ing_cost)/ Calculated total_DEC AS discount,
           (Calculated total_DEC*(1-.82)) format=8.2 AS target_ing_cost,
           (Calculated total_DEC-Calculated target_ing_cost)/ Calculated total_DEC AS target_discount  
      FROM EGTASK.DATA_EXAMPLE;
QUIT;

data TEST_2;
  set TEST;
  do i=.8 to 1.2 by .01;
    target_cost = Price*Quantity*i;
	output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want is to accomplish what is being done in the data step in the PROC SQL instead (do it in one step). Is this possible?&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 15:44:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-loop-within-PROC-SQL/m-p/358267#M64314</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2017-05-12T15:44:58Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop within PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-loop-within-PROC-SQL/m-p/358272#M64315</link>
      <description>&lt;P&gt;Why not just make the list of values as a separate table and join with it?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data list_of_values;
  do i=.8 to 1.2 by .01;
    output;
  end;
run;

proc sql;
create table TEST as 
  select a.*
       , a.price*a.quantity*b.I as target_cost
  from (
    select Quantity
         , Price
         , sum(DEC) as total_DEC
         , sum(Ingredient_Cost) as total_ing_cost
         , (Calculated total_DEC-Calculated total_ing_cost)/ Calculated total_DEC as discount
         , (Calculated total_DEC*(1-.82)) format=8.2 as target_ing_cost
         , (Calculated total_DEC-Calculated target_ing_cost)/ Calculated total_DEC as target_discount
    from EGTasK.DATA_EXAMPLE 
        ) a
     , list_of_values b
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 May 2017 16:02:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-loop-within-PROC-SQL/m-p/358272#M64315</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-05-12T16:02:57Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop within PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-loop-within-PROC-SQL/m-p/358276#M64316</link>
      <description>Tom beat me to it!  "Do this thing for each of these values" -- in SQL, you express that via a join.</description>
      <pubDate>Fri, 12 May 2017 16:16:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-loop-within-PROC-SQL/m-p/358276#M64316</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2017-05-12T16:16:06Z</dc:date>
    </item>
  </channel>
</rss>

