<?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: Converting a PROC SQL step into a DATA step in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Converting-a-PROC-SQL-step-into-a-DATA-step/m-p/853857#M10761</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/437707"&gt;@Ogalah&lt;/a&gt;&amp;nbsp;I feel you need to explain clearly what you have and what you want to do. Right now it's a bit confusing. In regards of what you have: Please be clear what's already fully working and what's only some code in the middle of trials.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want to keep data in SQL Server or are you trying to replicate/migrate the tables to SAS and maintain it in SAS?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or based on the initial code you've posted: Are you trying to create multiple delta files in SAS that then get used to update a master table in SQL server?&lt;/P&gt;
&lt;P&gt;Please explain us the process you want to implement and where data needs to be stored. The one thing you need to avoid for performance reasons are unnecessary data movements between the data base and SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To start with the SQL Server code you've posted after removing all lines in comment:&lt;/P&gt;
&lt;PRE&gt;SET ANSI_WARNINGS OFF

DECLARE @DATE VARCHAR(255)

SET @DATE = (
		SELECT MAX(FileDate)
		FROM [SABC_LastRun]
		)

UPDATE [dbo].[A_TEST_ZSRS_POS_FILE_DS_JOHANNES]
SET ValidateReg = CASE 
		WHEN rtrim(ltrim(isnull(TVLIC_NUM, '0'))) = '0'
			THEN 'TVLIC_NUM'
		WHEN rtrim(ltrim(isnull(DEAL_LICNUM, '0'))) = '0'
			THEN 'DEAL_LICNUM'
		WHEN rtrim(ltrim(isnull(ID_NUMBER, ''))) = ''
			THEN 'ID_NUMBER'
		WHEN rtrim(ltrim(isnull(PUR_DATE, '1900-01-01'))) &amp;lt;= '1900-01-01'
			THEN 'PUR_DATE'
		WHEN rtrim(ltrim(isnull(TV_QTY, '0'))) = '0'
			THEN 'TV_QTY'
		WHEN rtrim(ltrim(isnull(REF_NUM, ''))) = ''
			THEN 'REF_NUM'
		WHEN TVLIC_TYPE IN (
				'4'
				,'5'
				)
			AND (
				rtrim(ltrim(isnull(DOC_NUM, ''))) = ''
				AND ltrim(rtrim(isnull(PAY_RCTNO, ''))) = ''
				)
			THEN 'DOC_NUM'
		WHEN (
				TVLIC_TYPE IN (
					'4'
					,'5'
					)
				OR (TVLIC_TYPE = '3')
				) -- and PRODUCTCODE in ('07','40')))
			AND rtrim(ltrim(isnull(TITLE, ''))) = ''
			AND rtrim(ltrim(isnull(INITIALS, ''))) = ''
			AND rtrim(ltrim(isnull(CUST_NAME, ''))) = ''
			THEN 'Title, Initials and Name'
		WHEN (
				rtrim(ltrim(isnull(ADD_BLDG, ''))) = ''
				AND rtrim(ltrim(isnull(ADD_BLDGNM, ''))) = ''
				AND rtrim(ltrim(isnull(ADD_STRTNAM, ''))) = ''
				AND rtrim(ltrim(isnull(ADD_STRTNUM, ''))) = ''
				AND rtrim(ltrim(isnull(ADD_CITY, ''))) = ''
				AND rtrim(ltrim(isnull(ADD_RPCODE, ''))) = ''
				)
			AND (
				rtrim(ltrim(isnull(ADD_POST1, ''))) = ''
				AND rtrim(ltrim(isnull(ADD_POST2, ''))) = ''
				AND rtrim(ltrim(isnull(ADD_POST3, ''))) = ''
				AND rtrim(ltrim(isnull(ADD_POST4, ''))) = ''
				AND rtrim(ltrim(isnull(ADD_PPCODE, ''))) = ''
				)
			THEN 'Addresses'
		ELSE 'Success'
		END
WHERE isnull([REGProcessed], 0) = 0 -- Only process records previously not processed
	AND isnull(Validatereg, '') &amp;lt;&amp;gt; 'Success' -- that validated unsuccessfully on business rules
	AND ZPAY_DATE &amp;gt;= @DATE;
&lt;/PRE&gt;
&lt;P&gt;All the SQL Server expressions like below that check for blank only or NULL values...&lt;/P&gt;
&lt;PRE&gt;when rtrim(ltrim(isnull(ID_NUMBER, ''))) = '' THEN 'ID_NUMBER'&lt;/PRE&gt;
&lt;P&gt;....could be formulated in SAS syntax for both numerical and character variables like below.&lt;/P&gt;
&lt;PRE&gt;when missing(ID_NUMBER) THEN 'ID_NUMBER'&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This portion of the SQL Server syntax....&lt;/P&gt;
&lt;PRE&gt;DECLARE @DATE VARCHAR(255)

SET @DATE = (
		SELECT MAX(FileDate)
		FROM [SABC_LastRun]
		)&lt;/PRE&gt;
&lt;P&gt;...could likely look in SAS like... (depending if columns FileDate and ZPAY_DATE contain strings, SAS date or SAS DateTime values).&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
  select put(max(file_date),32.) into :date trimmed
  from &amp;lt;libref TBD&amp;gt;.SABC_LastRun;
quit;

.....
and AND ZPAY_DATE &amp;gt;= &amp;amp;date.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 14 Jan 2023 04:20:18 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2023-01-14T04:20:18Z</dc:date>
    <item>
      <title>Converting a PROC SQL step into a DATA step</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Converting-a-PROC-SQL-step-into-a-DATA-step/m-p/853652#M10755</link>
      <description>&lt;P&gt;Greetings,&lt;BR /&gt;&lt;BR /&gt;I am writing a program that needs to generate some files below are the validation rules extracted from SQL.&lt;BR /&gt;how can I convert it into a data step maintaining the same logic/rules&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;&lt;BR /&gt;	create table Payment_files as select * from HANADB1.ZSRS_POS_FILE where &lt;BR /&gt;		compress(ACC_IND) ^='' AND (compress (DOC_NUM) ^='' or compress(POS_TXN) &lt;BR /&gt;		^='') And PAY_AMOUNT &amp;gt; 0 And compress(REF_NUM)^='' and (USE_IND='X' or &lt;BR /&gt;		PAY_METHOD in('2', '4')) and TRAN_CODE^='' and PAY_RCTNO ^='';&lt;BR /&gt;	if index(BU_CODE, 'HF') &amp;gt; 0 then do;&lt;BR /&gt;	Chain='Hifi_Corporation';&lt;BR /&gt;	output Paymnent_HF;&lt;BR /&gt;	end;&lt;BR /&gt;	else if index(BU_CODE, 'IC') &amp;gt; 0 then do;&lt;BR /&gt;	Chain='Incredible_Connection';&lt;BR /&gt;	output Paymenr_IC;&lt;BR /&gt;	end;&lt;BR /&gt;	else do Chain='JD_Home';&lt;BR /&gt;	output Register_File_Retail;&lt;BR /&gt;	end;&lt;BR /&gt;	where input(PUR_DATE, 20.)=&amp;amp;todaysDate -2;&lt;BR /&gt;quit;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;NB: the original code&amp;nbsp; in SQL&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;update A_TEST_ZSRS_POS_FILE_DS_JOHANNES&lt;BR /&gt;set&lt;BR /&gt;Validatepay = case&lt;BR /&gt;when ACC_IND &amp;lt;&amp;gt; ' '&lt;BR /&gt;AND (ltrim(rtrim(isnull(DOC_NUM,''))) &amp;lt;&amp;gt; ''&lt;BR /&gt;or&lt;BR /&gt;ltrim(rtrim(isnull(POS_TXN,''))) &amp;lt;&amp;gt; '')&lt;BR /&gt;AND cast(PAY_AMOUNT as money) &amp;gt; 0.00&lt;BR /&gt;AND ltrim(rtrim(isnull(REF_NUM,''))) &amp;lt;&amp;gt; ''&lt;BR /&gt;AND (&lt;BR /&gt;USE_IND = 'X'&lt;BR /&gt;OR PAY_METHOD IN (&lt;BR /&gt;'2'&lt;BR /&gt;,'4'&lt;BR /&gt;)&lt;BR /&gt;) -- here we want to include all Credit sales (3) that was used in SRS (X), as well as all CASH sales (2 and 4)&lt;/P&gt;&lt;P&gt;AND TRAN_CODE &amp;lt;&amp;gt; ''&lt;BR /&gt;and PAY_RCTNO &amp;lt;&amp;gt; ''&lt;BR /&gt;then 'Success'&lt;BR /&gt;when USE_IND &amp;lt;&amp;gt; 'X'&lt;BR /&gt;AND PAY_METHOD NOT IN (&lt;BR /&gt;'2'&lt;BR /&gt;,'4'&lt;BR /&gt;) then 'Filtered'&lt;BR /&gt;else ''+&lt;BR /&gt;case when ACC_IND = ' ' then 'Acc_Ind ' else '' end +&lt;BR /&gt;case when cast(PAY_AMOUNT as money) = 0.00 then 'Pay_Amount ' else '' end +&lt;BR /&gt;case when cast(PAY_AMOUNT as money) = 0.00 and TVLIC_TYPE = '4' then 'Existing ' else '' end +&lt;BR /&gt;case when ltrim(rtrim(isnull(REF_NUM,''))) = '' then 'Ref_Num ' else '' end +&lt;BR /&gt;case when cast(PAY_AMOUNT as money) &amp;lt; 0.00 then 'Pay_Amount Negative ' else '' end +&lt;BR /&gt;case when TRAN_CODE = '' then 'Tran_code ' else '' end +&lt;BR /&gt;case when PAY_RCTNO = '' then 'PAY_RCTNO ' else '' end +&lt;BR /&gt;''&lt;BR /&gt;end,&lt;BR /&gt;DOC_NUM = case&lt;BR /&gt;when ltrim(rtrim(isnull(DOC_NUM,''))) = '' then POS_TXN&lt;BR /&gt;else DOC_NUM&lt;BR /&gt;end&lt;BR /&gt;where isnull(PMTProcessed,0) = 0&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 10:44:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Converting-a-PROC-SQL-step-into-a-DATA-step/m-p/853652#M10755</guid>
      <dc:creator>Ogalah</dc:creator>
      <dc:date>2023-01-13T10:44:45Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a PROC SQL step into a DATA step</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Converting-a-PROC-SQL-step-into-a-DATA-step/m-p/853669#M10756</link>
      <description>&lt;P&gt;If you are going to provide "original code " provide all of it. There is no FROM so that code is incomplete.&lt;/P&gt;
&lt;P&gt;You might be hiding some sort of JOIN in the data source.&lt;/P&gt;
&lt;P&gt;We don't know if there is any Groupby applied.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And SQL update can be a bit finicky and I'm not sure whether a data step exactly does the same things as SQL update.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 11:07:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Converting-a-PROC-SQL-step-into-a-DATA-step/m-p/853669#M10756</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-01-13T11:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a PROC SQL step into a DATA step</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Converting-a-PROC-SQL-step-into-a-DATA-step/m-p/853689#M10757</link>
      <description>SET ansi_warnings OFF&lt;BR /&gt;&lt;BR /&gt;DECLARE @DATE VARCHAR(255)&lt;BR /&gt;&lt;BR /&gt;SET @DATE = (select MAX(FileDate) from [SABC_LastRun])&lt;BR /&gt;--DECLARE @Lday VARCHAR(255)&lt;BR /&gt;--DECLARE @Dday VARCHAR(255)&lt;BR /&gt;--DECLARE @Lmnth VARCHAR(255)&lt;BR /&gt;--DECLARE @month VARCHAR(255)&lt;BR /&gt;--DECLARE @day VARCHAR(255)&lt;BR /&gt;--DECLARE @curdate datetime;&lt;BR /&gt;--DECLARE @year VARCHAR(255)&lt;BR /&gt;--DECLARE @LENT VARCHAR(255)&lt;BR /&gt;--DECLARE @MLENT VARCHAR(255)&lt;BR /&gt;&lt;BR /&gt;--set @year = (SELECT YEAR(@curdate))&lt;BR /&gt;--set @month = (SELECT MONTH(GETDATE()-1));&lt;BR /&gt;--set @day = (SELECT MONTH(GETDATE()));&lt;BR /&gt;--SET @curdate = GETDATE()&lt;BR /&gt;--SET @Lday =(SELECT DATEADD(MONTH,1+DATEDIFF(MONTH,0,@curdate),1));&lt;BR /&gt;--SET @Lday = (SELECT DAY(@curdate))&lt;BR /&gt;--set @month = (SELECT MONTH(@curdate));&lt;BR /&gt;&lt;BR /&gt;--SET @Dday =(SELECT&lt;BR /&gt;--REPLICATE('0', 1) + @Lday)&lt;BR /&gt;----Day end&lt;BR /&gt;--SET @Dday = (SELECT DAY(@curdate))&lt;BR /&gt;--if(@Dday != 01 )&lt;BR /&gt;--BEGIN&lt;BR /&gt;--set @year = (SELECT YEAR(@curdate))&lt;BR /&gt;--SET @Dday = (SELECT DAY(@curdate)-1)&lt;BR /&gt;--set @month = (SELECT MONTH(@curdate))&lt;BR /&gt;--set @year = (SELECT YEAR(@curdate))&lt;BR /&gt;--SET @LENT =(SELECT LEN(@Dday))&lt;BR /&gt;--SET @MLENT =(SELECT LEN(@month))&lt;BR /&gt;&lt;BR /&gt;--IF(@LENT=1)&lt;BR /&gt;--SET @Dday =(SELECT&lt;BR /&gt;--REPLICATE('0', 2-(@Dday)) + @Dday)&lt;BR /&gt;--IF(@MLENT=1)&lt;BR /&gt;--SET @month =(SELECT&lt;BR /&gt;--REPLICATE('0', 2-LEN(@month)) + @month)&lt;BR /&gt;--ELSE&lt;BR /&gt;&lt;BR /&gt;--SET @DATE= @year+'-'+@month+'-'+@Dday&lt;BR /&gt;&lt;BR /&gt;--END&lt;BR /&gt;&lt;BR /&gt;----Month end&lt;BR /&gt;--if(@Lday = 01 AND @month !=01 )&lt;BR /&gt;--BEGIN&lt;BR /&gt;--set @year = (SELECT YEAR(@curdate))&lt;BR /&gt;--SET @Lday =(SELECT DATEADD(MONTH,1+DATEDIFF(MONTH,0,GETDATE()),1));&lt;BR /&gt;--SET @Lday = (SELECT DAY(@curdate))&lt;BR /&gt;--set @month = (SELECT MONTH(@curdate)-1);&lt;BR /&gt;--SET @LENT =(SELECT LEN(@Dday))&lt;BR /&gt;&lt;BR /&gt;--IF(@LENT=1)&lt;BR /&gt;--SET @Lday =(SELECT&lt;BR /&gt;--REPLICATE('0', 1) + @Lday)&lt;BR /&gt;--IF(@MLENT=1)&lt;BR /&gt;--SET @month =(SELECT&lt;BR /&gt;--REPLICATE('0', 1) + @month)&lt;BR /&gt;--ELSE&lt;BR /&gt;--SET @Lday = (SELECT DAY(@curdate))&lt;BR /&gt;--SELECT @date = @year+'-'+@month+'-'+@Lday&lt;BR /&gt;--SET @date =(SELECT DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, @date) + 1, 0)))&lt;BR /&gt;--SET @Lday = (SELECT DAY(@date))&lt;BR /&gt;--SET @DATE = @year+'-'+@month+'-'+@Lday&lt;BR /&gt;--END&lt;BR /&gt;----Year end&lt;BR /&gt;--DECLARE @CYEAR VARCHAR(255)&lt;BR /&gt;--DECLARE @LYEAR VARCHAR(255)&lt;BR /&gt;--DECLARE @FYEAR VARCHAR(255)&lt;BR /&gt;--DECLARE @FDATE VARCHAR(255)&lt;BR /&gt;--DECLARE @YDATE VARCHAR(255)&lt;BR /&gt;--SET @LYEAR = (SELECT YEAR(GETDATE()))&lt;BR /&gt;--SET @CYEAR = (SELECT YEAR(@curdate))&lt;BR /&gt;--SET @YDATE = @CYEAR+'-'+@month+'-'+@Lday&lt;BR /&gt;--if(@YDATE = @LYEAR+'-'+'1'+'-'+'1')&lt;BR /&gt;--BEGIN&lt;BR /&gt;--SET @CYEAR = (SELECT YEAR(@curdate)-1);&lt;BR /&gt;--set @month = 12 ;&lt;BR /&gt;--SET @DATE = @CYEAR+'-'+'12'+'-'+'31';&lt;BR /&gt;--END&lt;BR /&gt;&lt;BR /&gt;update [dbo].[A_TEST_ZSRS_POS_FILE_DS_JOHANNES]&lt;BR /&gt;set ValidateReg = case&lt;BR /&gt;when rtrim(ltrim(isnull(TVLIC_NUM,'0'))) = '0' then 'TVLIC_NUM'&lt;BR /&gt;when rtrim(ltrim(isnull(DEAL_LICNUM,'0'))) = '0' then 'DEAL_LICNUM'&lt;BR /&gt;when rtrim(ltrim(isnull(ID_NUMBER,''))) = '' then 'ID_NUMBER'&lt;BR /&gt;when rtrim(ltrim(isnull(PUR_DATE,'1900-01-01'))) &amp;lt;= '1900-01-01' then 'PUR_DATE'&lt;BR /&gt;when rtrim(ltrim(isnull(TV_QTY,'0'))) = '0' then 'TV_QTY'&lt;BR /&gt;--when rtrim(ltrim(isnull(EASYPAYNUM,'0'))) = '0' then 'EASYPAYNUM'&lt;BR /&gt;when rtrim(ltrim(isnull(REF_NUM,''))) = '' then 'REF_NUM'&lt;BR /&gt;&lt;BR /&gt;--when TVLIC_TYPE in ('3','5')&lt;BR /&gt;--and rtrim(ltrim(isnull(PAY_RCTNO,'0'))) = '0'&lt;BR /&gt;-- then 'PAY_RCTNO'&lt;BR /&gt;when TVLIC_TYPE in ('4','5')&lt;BR /&gt;and (rtrim(ltrim(isnull(DOC_NUM,''))) = '' and ltrim(rtrim(isnull(PAY_RCTNO,''))) = '' )&lt;BR /&gt;then 'DOC_NUM'&lt;BR /&gt;when (TVLIC_TYPE in ('4','5')&lt;BR /&gt;or (TVLIC_TYPE = '3'))-- and PRODUCTCODE in ('07','40')))&lt;BR /&gt;and rtrim(ltrim(isnull(TITLE,''))) = ''&lt;BR /&gt;and rtrim(ltrim(isnull(INITIALS, ''))) = ''&lt;BR /&gt;and rtrim(ltrim(isnull(CUST_NAME, ''))) = ''&lt;BR /&gt;then 'Title, Initials and Name'&lt;BR /&gt;when (&lt;BR /&gt;rtrim(ltrim(isnull(ADD_BLDG,''))) = ''&lt;BR /&gt;and rtrim(ltrim(isnull(ADD_BLDGNM,''))) = ''&lt;BR /&gt;and rtrim(ltrim(isnull(ADD_STRTNAM,''))) = ''&lt;BR /&gt;and rtrim(ltrim(isnull(ADD_STRTNUM,''))) = ''&lt;BR /&gt;and rtrim(ltrim(isnull(ADD_CITY,''))) = ''&lt;BR /&gt;and rtrim(ltrim(isnull(ADD_RPCODE,''))) = '' )&lt;BR /&gt;and&lt;BR /&gt;(&lt;BR /&gt;rtrim(ltrim(isnull(ADD_POST1,''))) = ''&lt;BR /&gt;and rtrim(ltrim(isnull(ADD_POST2,''))) = ''&lt;BR /&gt;and rtrim(ltrim(isnull(ADD_POST3,''))) = ''&lt;BR /&gt;and rtrim(ltrim(isnull(ADD_POST4,''))) = ''&lt;BR /&gt;and rtrim(ltrim(isnull(ADD_PPCODE,''))) = '' )&lt;BR /&gt;then 'Addresses'&lt;BR /&gt;else 'Success'&lt;BR /&gt;end&lt;BR /&gt;where isnull([REGProcessed],0) = 0 -- Only process records previously not processed&lt;BR /&gt;and isnull(Validatereg,'') &amp;lt;&amp;gt; 'Success' -- that validated unsuccessfully on business rules&lt;BR /&gt;and ZPAY_DATE &amp;gt;= @DATE&lt;BR /&gt;</description>
      <pubDate>Fri, 13 Jan 2023 12:15:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Converting-a-PROC-SQL-step-into-a-DATA-step/m-p/853689#M10757</guid>
      <dc:creator>Ogalah</dc:creator>
      <dc:date>2023-01-13T12:15:29Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a PROC SQL step into a DATA step</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Converting-a-PROC-SQL-step-into-a-DATA-step/m-p/853823#M10759</link>
      <description>&lt;P&gt;You are obviously updating an external database. Do you want your DATA step version to also update the same database? Where is the data to update the database coming from and why do you want to convert it to a DATA step?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 22:00:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Converting-a-PROC-SQL-step-into-a-DATA-step/m-p/853823#M10759</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-01-13T22:00:13Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a PROC SQL step into a DATA step</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Converting-a-PROC-SQL-step-into-a-DATA-step/m-p/853857#M10761</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/437707"&gt;@Ogalah&lt;/a&gt;&amp;nbsp;I feel you need to explain clearly what you have and what you want to do. Right now it's a bit confusing. In regards of what you have: Please be clear what's already fully working and what's only some code in the middle of trials.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want to keep data in SQL Server or are you trying to replicate/migrate the tables to SAS and maintain it in SAS?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or based on the initial code you've posted: Are you trying to create multiple delta files in SAS that then get used to update a master table in SQL server?&lt;/P&gt;
&lt;P&gt;Please explain us the process you want to implement and where data needs to be stored. The one thing you need to avoid for performance reasons are unnecessary data movements between the data base and SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To start with the SQL Server code you've posted after removing all lines in comment:&lt;/P&gt;
&lt;PRE&gt;SET ANSI_WARNINGS OFF

DECLARE @DATE VARCHAR(255)

SET @DATE = (
		SELECT MAX(FileDate)
		FROM [SABC_LastRun]
		)

UPDATE [dbo].[A_TEST_ZSRS_POS_FILE_DS_JOHANNES]
SET ValidateReg = CASE 
		WHEN rtrim(ltrim(isnull(TVLIC_NUM, '0'))) = '0'
			THEN 'TVLIC_NUM'
		WHEN rtrim(ltrim(isnull(DEAL_LICNUM, '0'))) = '0'
			THEN 'DEAL_LICNUM'
		WHEN rtrim(ltrim(isnull(ID_NUMBER, ''))) = ''
			THEN 'ID_NUMBER'
		WHEN rtrim(ltrim(isnull(PUR_DATE, '1900-01-01'))) &amp;lt;= '1900-01-01'
			THEN 'PUR_DATE'
		WHEN rtrim(ltrim(isnull(TV_QTY, '0'))) = '0'
			THEN 'TV_QTY'
		WHEN rtrim(ltrim(isnull(REF_NUM, ''))) = ''
			THEN 'REF_NUM'
		WHEN TVLIC_TYPE IN (
				'4'
				,'5'
				)
			AND (
				rtrim(ltrim(isnull(DOC_NUM, ''))) = ''
				AND ltrim(rtrim(isnull(PAY_RCTNO, ''))) = ''
				)
			THEN 'DOC_NUM'
		WHEN (
				TVLIC_TYPE IN (
					'4'
					,'5'
					)
				OR (TVLIC_TYPE = '3')
				) -- and PRODUCTCODE in ('07','40')))
			AND rtrim(ltrim(isnull(TITLE, ''))) = ''
			AND rtrim(ltrim(isnull(INITIALS, ''))) = ''
			AND rtrim(ltrim(isnull(CUST_NAME, ''))) = ''
			THEN 'Title, Initials and Name'
		WHEN (
				rtrim(ltrim(isnull(ADD_BLDG, ''))) = ''
				AND rtrim(ltrim(isnull(ADD_BLDGNM, ''))) = ''
				AND rtrim(ltrim(isnull(ADD_STRTNAM, ''))) = ''
				AND rtrim(ltrim(isnull(ADD_STRTNUM, ''))) = ''
				AND rtrim(ltrim(isnull(ADD_CITY, ''))) = ''
				AND rtrim(ltrim(isnull(ADD_RPCODE, ''))) = ''
				)
			AND (
				rtrim(ltrim(isnull(ADD_POST1, ''))) = ''
				AND rtrim(ltrim(isnull(ADD_POST2, ''))) = ''
				AND rtrim(ltrim(isnull(ADD_POST3, ''))) = ''
				AND rtrim(ltrim(isnull(ADD_POST4, ''))) = ''
				AND rtrim(ltrim(isnull(ADD_PPCODE, ''))) = ''
				)
			THEN 'Addresses'
		ELSE 'Success'
		END
WHERE isnull([REGProcessed], 0) = 0 -- Only process records previously not processed
	AND isnull(Validatereg, '') &amp;lt;&amp;gt; 'Success' -- that validated unsuccessfully on business rules
	AND ZPAY_DATE &amp;gt;= @DATE;
&lt;/PRE&gt;
&lt;P&gt;All the SQL Server expressions like below that check for blank only or NULL values...&lt;/P&gt;
&lt;PRE&gt;when rtrim(ltrim(isnull(ID_NUMBER, ''))) = '' THEN 'ID_NUMBER'&lt;/PRE&gt;
&lt;P&gt;....could be formulated in SAS syntax for both numerical and character variables like below.&lt;/P&gt;
&lt;PRE&gt;when missing(ID_NUMBER) THEN 'ID_NUMBER'&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This portion of the SQL Server syntax....&lt;/P&gt;
&lt;PRE&gt;DECLARE @DATE VARCHAR(255)

SET @DATE = (
		SELECT MAX(FileDate)
		FROM [SABC_LastRun]
		)&lt;/PRE&gt;
&lt;P&gt;...could likely look in SAS like... (depending if columns FileDate and ZPAY_DATE contain strings, SAS date or SAS DateTime values).&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
  select put(max(file_date),32.) into :date trimmed
  from &amp;lt;libref TBD&amp;gt;.SABC_LastRun;
quit;

.....
and AND ZPAY_DATE &amp;gt;= &amp;amp;date.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Jan 2023 04:20:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Converting-a-PROC-SQL-step-into-a-DATA-step/m-p/853857#M10761</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-01-14T04:20:18Z</dc:date>
    </item>
  </channel>
</rss>

