<?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: Convert to data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-to-data-step/m-p/644651#M192583</link>
    <description>&lt;P&gt;From the look of your query you are reading from an external database. There is probably no point in converting this to a DATA step as behind the scenes SAS has to convert it back to SQL for external databases anyway. You could try using SQL passthru instead of the implicit SQL you are using.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For large data extracts you will be limited by the network bandwidth between the database and SAS anyway. One way to prove exactly how long the database takes is to run your query without transmitting lots of data is to turn it into a simple row count:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
   select count(*) from 
   (SELECT t1.industrysegment AS ProdLvl_1, 
          t1.categorygroup AS ProdLvl_2, 
          t1.category AS ProdLvl_3, 
          t1.subcategory AS ProdLvl_4, 
          t1.itemnumberunsuppressed AS iItem_uns, 
          t1.outletfamily, 
          t1.outlet_storeid, 
          t1.ppmonth, 
          t1.ppweek, 
          /* Dollars */
            (SUM(t1.totalvalue)) AS Dollars, 
          /* Units */
            (SUM(t1.unitssold)) AS Units
      FROM TECSWP2.vw_tecmlwk_fact_nc_uns t1
      WHERE t1.subcategory IN 
           (
           60638,
           60640
           ) AND t1.totalvalue &amp;gt;= 1 AND t1.unitssold &amp;gt;= 1 AND t1.ppmonth BETWEEN &amp;amp;Month-23 and &amp;amp;Month
      GROUP BY t1.industrysegment,
               t1.categorygroup,
               t1.category,
               t1.subcategory,
               t1.itemnumberunsuppressed,
               t1.outletfamily,
               t1.outlet_storeid,
               t1.ppmonth,
               t1.ppweek
   );
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 02 May 2020 02:20:15 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2020-05-02T02:20:15Z</dc:date>
    <item>
      <title>Convert to data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-to-data-step/m-p/644635#M192576</link>
      <description>&lt;P&gt;Howdy,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I work at a data company and pull data all day :-).&amp;nbsp; Some of our tables are large and the initial data pull can take a while.&amp;nbsp; Is there a more efficient way than PROC SQL?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a typical data pull.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jeff&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
   CREATE TABLE WORK.TECH_01 AS 
   SELECT t1.industrysegment AS ProdLvl_1, 
          t1.categorygroup AS ProdLvl_2, 
          t1.category AS ProdLvl_3, 
          t1.subcategory AS ProdLvl_4, 
          t1.itemnumberunsuppressed AS iItem_uns, 
          t1.outletfamily, 
          t1.outlet_storeid, 
          t1.ppmonth, 
          t1.ppweek, 
          /* Dollars */
            (SUM(t1.totalvalue)) AS Dollars, 
          /* Units */
            (SUM(t1.unitssold)) AS Units
      FROM TECSWP2.vw_tecmlwk_fact_nc_uns t1
      WHERE t1.subcategory IN 
           (
           60638,
           60640
           ) AND t1.totalvalue &amp;gt;= 1 AND t1.unitssold &amp;gt;= 1 AND t1.ppmonth BETWEEN &amp;amp;Month-23 and &amp;amp;Month
      GROUP BY t1.industrysegment,
               t1.categorygroup,
               t1.category,
               t1.subcategory,
               t1.itemnumberunsuppressed,
               t1.outletfamily,
               t1.outlet_storeid,
               t1.ppmonth,
               t1.ppweek;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 May 2020 23:50:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-to-data-step/m-p/644635#M192576</guid>
      <dc:creator>JeffM1968</dc:creator>
      <dc:date>2020-05-01T23:50:43Z</dc:date>
    </item>
    <item>
      <title>Re: Convert to data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-to-data-step/m-p/644648#M192581</link>
      <description>&lt;P&gt;This wouldn't be a data step, at best it could be a proc means but you SQL would be as efficient especially if its pulling from an RDBMS system.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm curious as to how you're storing month such that this works....&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;&amp;amp;Month-23&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=tecswp2.vw_tecmlwk_fact_nc_uns noprint NWAY;
where subcategory in (60638, 60640) and totalvalue&amp;gt;=1 and unitssold&amp;gt;=1 and ppmonth between  &amp;amp;Month-23 and &amp;amp;Month;

class [list your group by variables here];

var totalvalue unitssold;
output out=tech_01 sum(totalValue) = Dollars sum(unitssold) = Units;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can rename the variables in the same step on the OUT statement as well:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;output out=tech_01 (rename=(industrySegment = Prodlvl_1 categoryGroup=ProdLvl2) 
    sum(totalValue) = Dollars sum(unitssold) = Units;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That should be enough to get you going if you want to test out the performance difference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 May 2020 02:11:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-to-data-step/m-p/644648#M192581</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-05-02T02:11:33Z</dc:date>
    </item>
    <item>
      <title>Re: Convert to data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-to-data-step/m-p/644651#M192583</link>
      <description>&lt;P&gt;From the look of your query you are reading from an external database. There is probably no point in converting this to a DATA step as behind the scenes SAS has to convert it back to SQL for external databases anyway. You could try using SQL passthru instead of the implicit SQL you are using.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For large data extracts you will be limited by the network bandwidth between the database and SAS anyway. One way to prove exactly how long the database takes is to run your query without transmitting lots of data is to turn it into a simple row count:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
   select count(*) from 
   (SELECT t1.industrysegment AS ProdLvl_1, 
          t1.categorygroup AS ProdLvl_2, 
          t1.category AS ProdLvl_3, 
          t1.subcategory AS ProdLvl_4, 
          t1.itemnumberunsuppressed AS iItem_uns, 
          t1.outletfamily, 
          t1.outlet_storeid, 
          t1.ppmonth, 
          t1.ppweek, 
          /* Dollars */
            (SUM(t1.totalvalue)) AS Dollars, 
          /* Units */
            (SUM(t1.unitssold)) AS Units
      FROM TECSWP2.vw_tecmlwk_fact_nc_uns t1
      WHERE t1.subcategory IN 
           (
           60638,
           60640
           ) AND t1.totalvalue &amp;gt;= 1 AND t1.unitssold &amp;gt;= 1 AND t1.ppmonth BETWEEN &amp;amp;Month-23 and &amp;amp;Month
      GROUP BY t1.industrysegment,
               t1.categorygroup,
               t1.category,
               t1.subcategory,
               t1.itemnumberunsuppressed,
               t1.outletfamily,
               t1.outlet_storeid,
               t1.ppmonth,
               t1.ppweek
   );
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 May 2020 02:20:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-to-data-step/m-p/644651#M192583</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-05-02T02:20:15Z</dc:date>
    </item>
    <item>
      <title>Re: Convert to data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-to-data-step/m-p/644711#M192617</link>
      <description>&lt;P&gt;It is possible to redo your SQL as a data step. It may even be faster, if your database server is slow at calculating sums, and the connection between the server and your SAS machine is fast:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let byvars=industrysegment categorygroup category subcategory itemnumberunsuppressed outletfamily outlet_storeid ppmonth ppweek;
data WORK.TECH_01;
  set  TECSWP2.vw_tecmlwk_fact_nc_uns(keep=&amp;amp;byvars totalvalue unitssold);
  WHERE subcategory IN (60638,60640)
    AND totalvalue &amp;gt;= 1 AND unitssold &amp;gt;= 1 AND ppmonth BETWEEN &amp;amp;Month-23 and &amp;amp;Month;
  by &amp;amp;byvars;
  if first.%scan(&amp;amp;byvars,-1) then do;
   Dollars=totalvalue;
   Units=unitssold;
   end;
  else do;
   Dollars+totalvalue;
   Units+unitssold;
   end;
  if last.%scan(&amp;amp;byvars,-1);&lt;BR /&gt;  drop totalvalue unitssold;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But the data server still has to sort the data before delivering it to SAS, so there is no guarantee of a performance gain.&lt;/P&gt;</description>
      <pubDate>Sat, 02 May 2020 13:11:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-to-data-step/m-p/644711#M192617</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-05-02T13:11:48Z</dc:date>
    </item>
    <item>
      <title>Re: Convert to data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-to-data-step/m-p/644886#M192706</link>
      <description>It technically works but was slower than the PROC SQL so i'll stick with that.\&lt;BR /&gt;&lt;BR /&gt;Thanks anyway!!!</description>
      <pubDate>Sun, 03 May 2020 23:32:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-to-data-step/m-p/644886#M192706</guid>
      <dc:creator>JeffM1968</dc:creator>
      <dc:date>2020-05-03T23:32:22Z</dc:date>
    </item>
  </channel>
</rss>

