<?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: change data step to proc sql procedure in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/change-data-step-to-proc-sql-procedure/m-p/421980#M68008</link>
    <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first step I am doing (create an empty table for Proc_Step_Error_Log) is because it does not exist in the Oracle database initially. So that I want to add this part to avoid error.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once the table exists, I will delete step 1 procedure.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 18 Dec 2017 14:07:35 GMT</pubDate>
    <dc:creator>Crubal</dc:creator>
    <dc:date>2017-12-18T14:07:35Z</dc:date>
    <item>
      <title>change data step to proc sql procedure</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/change-data-step-to-proc-sql-procedure/m-p/421909#M68000</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a question changing this 'data step' procedure to 'proc sql' procedure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data Step Procedure: ('num_rec_prop' is a parameter that I have set and called)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Process_Step_Error_Log;
		if &amp;amp;num_rec_prop NE 1 then do;
			Step_ID = 001;
			Error_Code = 'AEE001';
		end;

		else do;
			Step_ID = 002;
			Error_Code = 'SUC001';
		end;
                output;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when I change this procedure into 'proc sql' and uses macro function. The reason is if there is an error, another table needs to be updated as well (PROC_STEP_LOG, and this table exists initially)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I create an empty table first:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	data Proc_Step_Error_Log;
		input Step_Id 10 Error_Code $10;
		datalines;
	run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Then, I use the following macro procedure: (proc_log_id is read and called before as well)&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro etl_error_log;
		%if &amp;amp;num_rec_prop NE 1 
			%then %do;
			insert into Proc_Step_Error_Log
				set Step_Id = 001
				  , Error_Code = "AEE001";

                          update PROC_STEP_LOG
				set 
					proc_step_end_ts = datetime()
					, proc_step_stat_cd = "Failed"
					, lst_updt_ts = datetime()
				where proc_log_id = &amp;amp;proc_log_id;
			%end;

                 %else %do;
			insert into Proc_Step_Error_Log
				set Step_Id = 002
				  , Error_Code = "SUC001";
			%end;
%mend;

%etl_error_log;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I ran this part, error message shows up:&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order. (Highlight on the word 'insert')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How could I fix my code to run successfully?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2017 05:40:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/change-data-step-to-proc-sql-procedure/m-p/421909#M68000</guid>
      <dc:creator>Crubal</dc:creator>
      <dc:date>2017-12-18T05:40:51Z</dc:date>
    </item>
    <item>
      <title>Re: change data step to proc sql procedure</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/change-data-step-to-proc-sql-procedure/m-p/421914#M68001</link>
      <description>&lt;P&gt;I see no proc sql statement, and no corresponding quit; to end the proc sql.&lt;/P&gt;
&lt;P&gt;Strong hint: always get your code to run without macro action before making it dynamic.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2017 07:00:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/change-data-step-to-proc-sql-procedure/m-p/421914#M68001</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-12-18T07:00:01Z</dc:date>
    </item>
    <item>
      <title>Re: change data step to proc sql procedure</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/change-data-step-to-proc-sql-procedure/m-p/421927#M68003</link>
      <description>&lt;P&gt;There really is no need for any macro code here.&amp;nbsp; Why do you need to change this into SQL, are you connecting to a database?&amp;nbsp; You can do it simply with a case:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  insert into etl_error_log
  set  stepid=case when &amp;amp;num_rec_prop. ne 1 then "001" else "002" end,
       error_code=case when &amp;amp;num_rec_prop. ne 1 then "AEE001" else "SUC001" end;
quit;&lt;/PRE&gt;
&lt;P&gt;However that being said, I would question why you are doing this in the first place.&amp;nbsp; What is the process, how are you getting the data in?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2017 09:22:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/change-data-step-to-proc-sql-procedure/m-p/421927#M68003</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-12-18T09:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: change data step to proc sql procedure</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/change-data-step-to-proc-sql-procedure/m-p/421966#M68005</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;Thanks for your reply!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;The reason I am changing the data procedure to proc sql is because the tables I try to update is in the Oracle.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2017 13:27:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/change-data-step-to-proc-sql-procedure/m-p/421966#M68005</guid>
      <dc:creator>Crubal</dc:creator>
      <dc:date>2017-12-18T13:27:15Z</dc:date>
    </item>
    <item>
      <title>Re: change data step to proc sql procedure</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/change-data-step-to-proc-sql-procedure/m-p/421968#M68006</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Absolutely right. It can work after adding this syntax.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2017 13:28:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/change-data-step-to-proc-sql-procedure/m-p/421968#M68006</guid>
      <dc:creator>Crubal</dc:creator>
      <dc:date>2017-12-18T13:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: change data step to proc sql procedure</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/change-data-step-to-proc-sql-procedure/m-p/421975#M68007</link>
      <description>&lt;P&gt;Well, step 1 is deciding where to do the work then.&amp;nbsp; There is no point in manipulating tables on a database from SAS, either download the data to SAS, process, then upload again, or do the processing on the database.&amp;nbsp; All your doing is hitting the large overhead of data transmittal back and forth.&amp;nbsp; If you do this on the database for instance you can set hooks on your dataset, which, when a condition is struck, inserts data automatically into the journal tables.&amp;nbsp; I would also question why the need for "Error" codes in the first place.&amp;nbsp; SAS is a data driven language, if no data is read in then the whole process can run and there would be no output, no need to generate an error system to catch these things as the code should run either way.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2017 13:45:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/change-data-step-to-proc-sql-procedure/m-p/421975#M68007</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-12-18T13:45:05Z</dc:date>
    </item>
    <item>
      <title>Re: change data step to proc sql procedure</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/change-data-step-to-proc-sql-procedure/m-p/421980#M68008</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first step I am doing (create an empty table for Proc_Step_Error_Log) is because it does not exist in the Oracle database initially. So that I want to add this part to avoid error.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once the table exists, I will delete step 1 procedure.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2017 14:07:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/change-data-step-to-proc-sql-procedure/m-p/421980#M68008</guid>
      <dc:creator>Crubal</dc:creator>
      <dc:date>2017-12-18T14:07:35Z</dc:date>
    </item>
  </channel>
</rss>

