<?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: DATA STEPS TO SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/DATA-STEPS-TO-SQL/m-p/234783#M42964</link>
    <description>Have you tried anything? This goes beyond the 'help' category and more like 'work' category.</description>
    <pubDate>Sat, 14 Nov 2015 22:48:10 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2015-11-14T22:48:10Z</dc:date>
    <item>
      <title>DATA STEPS TO SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-STEPS-TO-SQL/m-p/234781#M42962</link>
      <description>&lt;P&gt;&lt;SPAN&gt;have different data steps code, i need help to convert them to sql.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Could any one please help me with belwo data step codes to sql?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data w6.data3; set W6.data3;&lt;BR /&gt;data data4; set data3;&lt;BR /&gt;if SIC ge 6300 and SIC le 6350 then delete; /***Delete financial firms***/&lt;BR /&gt;if SIC ge 4900 and SIC le 4939 then delete; /***Delete utilities***/&lt;BR /&gt;if TACC_t eq . then delete;&lt;BR /&gt;if TA_t in (0, .) then delete;/***used to calculate ROA***/&lt;BR /&gt;if TA_tm1 in (0, .) then delete;/***used to calculate ROA***/&lt;BR /&gt;if Sales_t eq . then delete;&lt;BR /&gt;if Sales_tm1 eq . then delete;&lt;BR /&gt;if AR_ch_t eq . then delete;&lt;BR /&gt;if PPE_t eq . then delete;&lt;BR /&gt;if NI_t eq . then delete;&lt;BR /&gt;if NI_tm1 eq . then delete;&lt;BR /&gt;if AR_ch_t eq . then delete;&lt;BR /&gt;if MVE_tm1 eq 0 then delete; /*mused for extreme samples***/&lt;BR /&gt;Sales_ch_t = (Sales_t-Sales_tm1)/TA_tm1;&lt;BR /&gt;Sales_t=Sales_t/TA_tm1;&lt;BR /&gt;AR_ch_t=-AR_ch_t/TA_tm1;/***Note that accounts receivable change is (increase) decrease*/&lt;BR /&gt;Sales_rec_ch_t=Sales_ch_t-AR_ch_t;&lt;BR /&gt;if sales_rec_ch_t eq . then delete;&lt;BR /&gt;TACC_t=TACC_t/TA_tm1;&lt;BR /&gt;Int=1/TA_tm1;&lt;BR /&gt;EBEX_t=EBEX_t/TA_tm1;&lt;BR /&gt;CFO_t=CFO_t/TA_tm1;&lt;BR /&gt;PPE_t=PPE_t/TA_tm1;&lt;BR /&gt;ROA_t=(NI_t/TA_t);/***Current year net income over beginning total assets * */&lt;BR /&gt;ROA_tml=(NI_tm1/TA_tm1);/***Last year ROA***/&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sort data=data4; by SIC t;&lt;BR /&gt;data data4; set data4;&lt;BR /&gt;proc univariate noprint; var TACC_t;&lt;BR /&gt;output out=N n=N;&lt;BR /&gt;by SIC t; * t=yeara;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data data5; merge data4 N; /***4-digit SIC code Eliminate SIC t combination with less than 10 obs*/&lt;BR /&gt;by SIC t; if N &amp;lt; 10 then delete;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data data5; set data5;&lt;BR /&gt;proc reg noprint;&lt;BR /&gt;model TACC_t = Int Sales_rec_ch_t PPE_t ROA_t;&lt;BR /&gt;output out=pred11 p=ETAC1_t; /***r=DA0C1***/&lt;BR /&gt;model TACC_t = Int Sales_rec_ch_t PPE_t ROA_tm1;&lt;BR /&gt;output out=pred21 p=ETAC2_t /***r=DACC2***/;&lt;BR /&gt;by SIC t;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data pred1; set pred1;&lt;BR /&gt;DACC1=TACC_t-ETAC1_t;&lt;BR /&gt;proc sort; by cusip t;&lt;BR /&gt;data pred2; set pred2;&lt;BR /&gt;DACC2=TACC_t-ETAC2_t;&lt;BR /&gt;proc sort; by cusip t;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data data6; merge pred1 pred2;&lt;BR /&gt;by cusip t;&lt;BR /&gt;class=1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;______________________________________________&lt;BR /&gt;data study control; set data6;&lt;BR /&gt;if Class eq 1 then output study;&lt;BR /&gt;if Class eq 1 then output control;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Nov 2015 21:14:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-STEPS-TO-SQL/m-p/234781#M42962</guid>
      <dc:creator>however412</dc:creator>
      <dc:date>2015-11-14T21:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: DATA STEPS TO SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-STEPS-TO-SQL/m-p/234782#M42963</link>
      <description>&lt;P&gt;Do you mean SAS/SQL or some other version of SQL?&lt;/P&gt;</description>
      <pubDate>Sat, 14 Nov 2015 22:09:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-STEPS-TO-SQL/m-p/234782#M42963</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-11-14T22:09:56Z</dc:date>
    </item>
    <item>
      <title>Re: DATA STEPS TO SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-STEPS-TO-SQL/m-p/234783#M42964</link>
      <description>Have you tried anything? This goes beyond the 'help' category and more like 'work' category.</description>
      <pubDate>Sat, 14 Nov 2015 22:48:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-STEPS-TO-SQL/m-p/234783#M42964</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-11-14T22:48:10Z</dc:date>
    </item>
    <item>
      <title>Re: DATA STEPS TO SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-STEPS-TO-SQL/m-p/234787#M42965</link>
      <description>&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;Welcome to the SAS Support Communities!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you have noticed, it is technically possible to post the same question into different forums (such as "Base SAS Programming" and "General SAS Programming"). However, this is strongly discouraged, because people could think your question is unanswered while its copy has received a lot of response already.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, you want to convert data step code to SQL. May I ask, why do you want to translate your program into a language that you don't speak?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please consider that a typical program is revised many times until its final run. Therefore, I'd recommend that you do the editing in the existing code as this will be easier for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At least I can't believe that this is the final, translation-ready version of your program. For example, let's look at the last two data steps: The last but one step creates a work dataset DATA6 which contains a numeric variable CLASS whose value is 1 for each and every observation. The last data step looks as if it was to split DATA6 into two different datasets, STUDY and CONTROL, but in fact creates two exact copies of DATA6 by applying not only redundant, but obviously identical IF conditions to all observations of DATA6.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or look at the second data step: The repetitive "if &amp;lt;var&amp;gt; eq . then delete" statements could be simplified to a single subsetting IF statement of the form "if n(&amp;lt;var1&amp;gt;, &amp;lt;var2&amp;gt;, ...)" and so on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Moreover, your program is interspersed with PROC steps. Are these to be converted, too?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you say "SQL", which implementation do you mean? PROC SQL? [Oh, I see, PG has asked this already while I was typing this post.]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think it would help a lot if these issues and questions were resolved first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Nov 2015 23:38:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-STEPS-TO-SQL/m-p/234787#M42965</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-11-14T23:38:55Z</dc:date>
    </item>
    <item>
      <title>Re: DATA STEPS TO SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-STEPS-TO-SQL/m-p/234788#M42966</link>
      <description>&lt;P&gt;yes, i mean sas sql&lt;/P&gt;</description>
      <pubDate>Sun, 15 Nov 2015 00:16:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-STEPS-TO-SQL/m-p/234788#M42966</guid>
      <dc:creator>however412</dc:creator>
      <dc:date>2015-11-15T00:16:59Z</dc:date>
    </item>
    <item>
      <title>Re: DATA STEPS TO SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-STEPS-TO-SQL/m-p/234789#M42967</link>
      <description>&lt;P&gt;proc sql;&lt;BR /&gt;create table data w6.data3 as&lt;BR /&gt;select *&lt;BR /&gt;SIC ge = 6300 and SIC le = 6350 then delete&amp;nbsp;&lt;BR /&gt;SIC ge = 4900 and SIC le = 4939 then delete&lt;BR /&gt;TACC_t = eq . then delete&lt;BR /&gt;TA_t in (0, .) then delete&lt;BR /&gt;TA_tm1 in (0, .) then delete&lt;BR /&gt;Sales_t = eq . then delete&lt;BR /&gt;Sales_tm1 = eq . then delete&lt;BR /&gt;AR_ch_t = eq . then delete&lt;BR /&gt;PPE_t = eq . then delete&lt;BR /&gt;NI_t = eq . then delete&lt;BR /&gt;NI_tm1 = eq . then delete&lt;BR /&gt;AR_ch_t = eq . then delete&lt;BR /&gt;MVE_tm1 = eq 0 then delete&amp;nbsp;&lt;BR /&gt;Sales_ch_t = (Sales_t-Sales_tm1)/TA_tm1&lt;BR /&gt;Sales_t=Sales_t/TA_tm1&lt;BR /&gt;AR_ch_t=-AR_ch_t/TA_tm1&lt;BR /&gt;Sales_rec_ch_t=Sales_ch_t-AR_ch_t&lt;BR /&gt;sales_rec_ch_t = eq . then delete&lt;BR /&gt;TACC_t=TACC_t/TA_tm1&lt;BR /&gt;Int=1/TA_tm1&lt;BR /&gt;EBEX_t=EBEX_t/TA_tm1&lt;BR /&gt;CFO_t=CFO_t/TA_tm1&lt;BR /&gt;PPE_t=PPE_t/TA_tm1&lt;BR /&gt;ROA_t=(NI_t/TA_t)&amp;nbsp;&lt;BR /&gt;ROA_tml=(NI_tm1/TA_tm1)&amp;nbsp;&lt;/P&gt;&lt;P&gt;from w6.data3 ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE NOPRINT AS&lt;BR /&gt;SELECT*&lt;BR /&gt;where n=N&lt;BR /&gt;From data4 group by SIC t;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE DATA5SS;&lt;BR /&gt;SELECT *&lt;BR /&gt;FROM DATA5, DATA4&lt;BR /&gt;WHERE SIC t; N &amp;lt; 10 then delete;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;could you check this out? this what i have tried.&lt;/P&gt;</description>
      <pubDate>Sun, 15 Nov 2015 00:18:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-STEPS-TO-SQL/m-p/234789#M42967</guid>
      <dc:creator>however412</dc:creator>
      <dc:date>2015-11-15T00:18:57Z</dc:date>
    </item>
    <item>
      <title>Re: DATA STEPS TO SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-STEPS-TO-SQL/m-p/234791#M42968</link>
      <description>&lt;P&gt;What's the reason that you want to convert the data step into SQL?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your SQL skills look rater "beginner level" given the following:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select *
&lt;STRONG&gt;SIC ge = 6300 and SIC le = 6350 then delete&lt;/STRONG&gt; 
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;If you really want to use SQL code then I'd suggest that you probably first need to spend some time to skill-up in SQL syntax.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to exclude rows then you need to formulate your condition as part of a WHERE clause. It has nothing lost within the SELECT clause.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Nov 2015 01:36:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-STEPS-TO-SQL/m-p/234791#M42968</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-11-15T01:36:00Z</dc:date>
    </item>
    <item>
      <title>Re: DATA STEPS TO SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-STEPS-TO-SQL/m-p/234798#M42969</link>
      <description>&lt;P&gt;There is a nice conference paper &lt;A href="http://www2.sas.com/proceedings/forum2008/185-2008.pdf" target="_blank"&gt;PROC SQL for DATA Step Die-hards&lt;/A&gt;&amp;nbsp;to get you started with PROC SQL. I know an older version of it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then, if you want to go further, I can recommend Howard Schreier's excellent textbook &lt;A href="http://www.sas.com/store/books/categories/examples/proc-sql-by-example-using-sql-within-sas-/prodBK_60500_en.html" target="_blank"&gt;PROC SQL by Example&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Both of these resources contrast PROC SQL steps with similar DATA steps, which is ideal if you know the latter and want to learn the former.&lt;/P&gt;</description>
      <pubDate>Sun, 15 Nov 2015 09:38:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-STEPS-TO-SQL/m-p/234798#M42969</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-11-15T09:38:55Z</dc:date>
    </item>
    <item>
      <title>Re: DATA STEPS TO SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-STEPS-TO-SQL/m-p/234845#M42978</link>
      <description>&lt;P&gt;Just to add onto the good advice above, code formatting is also important. &amp;nbsp;Your code is very hard to read. &amp;nbsp;Use indentation, put each row on a new line, netsle blocks of code, finish blocks of code properly (e.g. run;). &amp;nbsp;As a helpful tip, there is above the box you type in a series of icons, {i} and the run sas symbols alow you post code directly, this keeps any of the formatting.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2015 10:09:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-STEPS-TO-SQL/m-p/234845#M42978</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-11-16T10:09:05Z</dc:date>
    </item>
  </channel>
</rss>

