<?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 Simplify This Proc SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Simplify-This-Proc-SQL/m-p/501998#M133943</link>
    <description>&lt;P&gt;Hi.&amp;nbsp; I'm wondering if there isn't a simpler way to accomplish what my code below is doing. For each record on my table there is a&amp;nbsp;&lt;SPAN&gt;CLM_BLG_PRVDR_NPI_NUM and a&amp;nbsp;CLM_RFRG_PRVDR_NPI_NUM.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;My requirement is to assign a Flag Indicator = 1 to each record where the associated&amp;nbsp;&lt;SPAN&gt;CLM_RFRG_PRVDR_NPI_NUM value is not also the same value as ANY record's&amp;nbsp; CLM_BLG_PRVDR_NPI_NUM value on the entire table. Otherwise the Flag Indicator should be 0.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;As you can see from my code below I accomplish this in two Proc SQL steps.&amp;nbsp; I'm interested to know if there is a simpler or more efficient way to get the same results in just one Proc SQL step?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any insights would be much appreciated!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;/* CREATE LIST OF RFRG NPI WHO HAVE NEVER BEEN A BLG NPI AND ASSIGN 1 AS A FLAG INDICATOR */&lt;BR /&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE RFRG_NEVER_BLG AS&lt;BR /&gt;SELECT&lt;BR /&gt;DISTINCT CLM_RFRG_PRVDR_NPI_NUM&lt;BR /&gt;,1 AS FLAG_IND&lt;BR /&gt;FROM NFPP_TRD.&amp;amp;USERN._ORTHOTICS_BASE_PULL_2&lt;BR /&gt;EXCEPT&lt;BR /&gt;SELECT DISTINCT CLM_BLG_PRVDR_NPI_NUM&lt;BR /&gt;,1 AS FLAG_IND&lt;BR /&gt;FROM NFPP_TRD.&amp;amp;USERN._ORTHOTICS_BASE_PULL_2&lt;BR /&gt;;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* MERGE ON THE RFRG NPI WHO HAVE NEVER BEEN A BLG NPI AND SET AN INDICATOR FLAG */&lt;BR /&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE F4_CL_ATRISK_V1 AS&lt;BR /&gt;SELECT T2.*&lt;BR /&gt;,CASE WHEN T1.FLAG_IND=1 THEN 1 ELSE 0 END AS FLAG_IND&lt;BR /&gt;FROM BASE_PULL_2 AS T2&lt;BR /&gt;LEFT JOIN RFRG_NEVER_BLG AS T1&lt;BR /&gt;ON T1.CLM_RFRG_PRVDR_NPI_NUM = T2.CLM_RFRG_PRVDR_NPI_NUM&lt;BR /&gt;;QUIT;&lt;/P&gt;</description>
    <pubDate>Fri, 05 Oct 2018 17:09:52 GMT</pubDate>
    <dc:creator>buechler66</dc:creator>
    <dc:date>2018-10-05T17:09:52Z</dc:date>
    <item>
      <title>Simplify This Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-This-Proc-SQL/m-p/501998#M133943</link>
      <description>&lt;P&gt;Hi.&amp;nbsp; I'm wondering if there isn't a simpler way to accomplish what my code below is doing. For each record on my table there is a&amp;nbsp;&lt;SPAN&gt;CLM_BLG_PRVDR_NPI_NUM and a&amp;nbsp;CLM_RFRG_PRVDR_NPI_NUM.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;My requirement is to assign a Flag Indicator = 1 to each record where the associated&amp;nbsp;&lt;SPAN&gt;CLM_RFRG_PRVDR_NPI_NUM value is not also the same value as ANY record's&amp;nbsp; CLM_BLG_PRVDR_NPI_NUM value on the entire table. Otherwise the Flag Indicator should be 0.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;As you can see from my code below I accomplish this in two Proc SQL steps.&amp;nbsp; I'm interested to know if there is a simpler or more efficient way to get the same results in just one Proc SQL step?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any insights would be much appreciated!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;/* CREATE LIST OF RFRG NPI WHO HAVE NEVER BEEN A BLG NPI AND ASSIGN 1 AS A FLAG INDICATOR */&lt;BR /&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE RFRG_NEVER_BLG AS&lt;BR /&gt;SELECT&lt;BR /&gt;DISTINCT CLM_RFRG_PRVDR_NPI_NUM&lt;BR /&gt;,1 AS FLAG_IND&lt;BR /&gt;FROM NFPP_TRD.&amp;amp;USERN._ORTHOTICS_BASE_PULL_2&lt;BR /&gt;EXCEPT&lt;BR /&gt;SELECT DISTINCT CLM_BLG_PRVDR_NPI_NUM&lt;BR /&gt;,1 AS FLAG_IND&lt;BR /&gt;FROM NFPP_TRD.&amp;amp;USERN._ORTHOTICS_BASE_PULL_2&lt;BR /&gt;;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* MERGE ON THE RFRG NPI WHO HAVE NEVER BEEN A BLG NPI AND SET AN INDICATOR FLAG */&lt;BR /&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE F4_CL_ATRISK_V1 AS&lt;BR /&gt;SELECT T2.*&lt;BR /&gt;,CASE WHEN T1.FLAG_IND=1 THEN 1 ELSE 0 END AS FLAG_IND&lt;BR /&gt;FROM BASE_PULL_2 AS T2&lt;BR /&gt;LEFT JOIN RFRG_NEVER_BLG AS T1&lt;BR /&gt;ON T1.CLM_RFRG_PRVDR_NPI_NUM = T2.CLM_RFRG_PRVDR_NPI_NUM&lt;BR /&gt;;QUIT;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 17:09:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-This-Proc-SQL/m-p/501998#M133943</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2018-10-05T17:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify This Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-This-Proc-SQL/m-p/502002#M133947</link>
      <description>What is the flag used for?&lt;BR /&gt;You can likely use the NODUPKEY or NOUNIQUEKEY to split the data into duplicates.</description>
      <pubDate>Fri, 05 Oct 2018 17:20:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-This-Proc-SQL/m-p/502002#M133947</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-05T17:20:25Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify This Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-This-Proc-SQL/m-p/502010#M133951</link>
      <description>&lt;P&gt;This?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE F4_CL_ATRISK_V1 AS
select 
    *, 
    CLM_RFRG_PRVDR_NPI_NUM not in (select CLM_BLG_PRVDR_NPI_NUM from BASE_PULL_2) as flag
FROM BASE_PULL_2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 18:07:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-This-Proc-SQL/m-p/502010#M133951</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-10-05T18:07:13Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify This Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-This-Proc-SQL/m-p/502015#M133953</link>
      <description>&lt;P&gt;You can use the first query as a sub-query in second.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE F4_CL_ATRISK_V1 AS
SELECT T2.*, CLM_RFRG_PRVDR_NPI_NUM not in (SELECT DISTINCT CLM_RFRG_PRVDR_NPI_NUM
						FROM NFPP_TRD.&amp;amp;USERN._ORTHOTICS_BASE_PULL_2
						 WHERE CLM_RFRG_PRVDR_NPI_NUM not in ( SELECT DISTINCT CLM_BLG_PRVDR_NPI_NUM
											FROM NFPP_TRD.&amp;amp;USERN._ORTHOTICS_BASE_PULL_2)
											) as Flag
FROM BASE_PULL_2 AS T2
ON T1.CLM_RFRG_PRVDR_NPI_NUM = T2.CLM_RFRG_PRVDR_NPI_NUM
;QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;OR&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE F4_CL_ATRISK_V1 AS
SELECT T2.*,CLM_RFRG_PRVDR_NPI_NUM not in (	SELECT DISTINCT CLM_RFRG_PRVDR_NPI_NUM
											FROM NFPP_TRD.&amp;amp;USERN._ORTHOTICS_BASE_PULL_2
										EXCEPT
											SELECT DISTINCT CLM_BLG_PRVDR_NPI_NUM
											FROM NFPP_TRD.&amp;amp;USERN._ORTHOTICS_BASE_PULL_2) as flag
FROM BASE_PULL_2 AS T2
;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Oct 2018 18:45:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-This-Proc-SQL/m-p/502015#M133953</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-10-05T18:45:16Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify This Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-This-Proc-SQL/m-p/502016#M133954</link>
      <description>Thank you for taking the time to help. I appreciate it.</description>
      <pubDate>Fri, 05 Oct 2018 18:48:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-This-Proc-SQL/m-p/502016#M133954</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2018-10-05T18:48:34Z</dc:date>
    </item>
  </channel>
</rss>

