<?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 Querying SQL database using SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Querying-SQL-database-using-SAS/m-p/761489#M240981</link>
    <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;I hope everyone is doing fine.&lt;/P&gt;&lt;P&gt;I have a challenge using SQL in SAS that I would really appreciate any assistance here.&lt;/P&gt;&lt;P&gt;Basically, I am querying a database and selecting specific columns, but I want to search one of the columns (containing provider IDs) for a multiple IDs. At the same time, I want to link the search to another column (containing facility IDs) for another list of multiple facility IDs, and then finally limit the search to exactly 2 years from a date provided in one of the columns. &amp;nbsp;Example of the fields/columns for my search is below. My actual table contains hundred’s of rows!&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Prov_ID&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Fac_id&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;1111114441&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;670010&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;23-Jul-2020&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;2387501187&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;876500&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;3-Sep-2020&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;9016661166&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;761122&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;15-Sep-2020&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;6724980729&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;865110&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;25-Jun-2020&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My challenge is finding a query/code to automate this search without having to write a new search query for each of my provider IDs, Facility IDs, and dates.&lt;/P&gt;&lt;P&gt;I used a code/query below and got results for the first facility ID and provider ID, but do not want to have to repeat for all the provider IDs and facility IDs I have.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%LET sql=%STR(CREATE TABLE &amp;amp;myschema..test AS&lt;BR /&gt;SELECT i.bene_clm_acnt_num,&lt;BR /&gt;i.clm_atndg_physn_npi_num,&lt;BR /&gt;i.clm_atndg_physn_srnm_name,&lt;BR /&gt;i.prvdr_num,&lt;BR /&gt;&lt;BR /&gt;i.bene_race_cd,&lt;BR /&gt;&lt;BR /&gt;i.clm_from_dt AS clm_from_dt1,&lt;BR /&gt;&lt;BR /&gt;i.bene_rsdnc_ssa_std_state_cd,&lt;BR /&gt;i.bene_birth_dt,&lt;BR /&gt;i.clm_pmt_amt,&lt;BR /&gt;i.org_npi_num,&lt;BR /&gt;i.clm_from_dt as clm_admsn_dt,&lt;BR /&gt;i.clm_thru_dt as discharge_dt,&lt;BR /&gt;i.mbi_id,&lt;BR /&gt;b.first_name,&lt;BR /&gt;b.last_name,&lt;BR /&gt;b.claim_account_number,&lt;BR /&gt;b.beneficiary_identification_code as BeneHICN&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;FROM nch_part_a.ipsn_header i&lt;BR /&gt;join beneficiary_data.beneficiary_status b on b.claim_account_number =i.bene_clm_acnt_num&lt;BR /&gt;WHERE&lt;BR /&gt;fac-id ='190002' and&lt;BR /&gt;prov_id = '1265622732'&lt;BR /&gt;and DATE_FORMAT(clm_thru_dt, 'yyyyMMdd') &amp;gt;= '20180801'&lt;BR /&gt;and DATE_FORMAT(clm_thru_dt, 'yyyyMMdd') &amp;lt;= '20200801'&lt;BR /&gt;);&lt;/P&gt;&lt;P&gt;I will grateful if someone can help me with this.&lt;/P&gt;</description>
    <pubDate>Fri, 13 Aug 2021 19:25:39 GMT</pubDate>
    <dc:creator>Rahim9</dc:creator>
    <dc:date>2021-08-13T19:25:39Z</dc:date>
    <item>
      <title>Querying SQL database using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Querying-SQL-database-using-SAS/m-p/761489#M240981</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;I hope everyone is doing fine.&lt;/P&gt;&lt;P&gt;I have a challenge using SQL in SAS that I would really appreciate any assistance here.&lt;/P&gt;&lt;P&gt;Basically, I am querying a database and selecting specific columns, but I want to search one of the columns (containing provider IDs) for a multiple IDs. At the same time, I want to link the search to another column (containing facility IDs) for another list of multiple facility IDs, and then finally limit the search to exactly 2 years from a date provided in one of the columns. &amp;nbsp;Example of the fields/columns for my search is below. My actual table contains hundred’s of rows!&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Prov_ID&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Fac_id&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;1111114441&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;670010&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;23-Jul-2020&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;2387501187&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;876500&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;3-Sep-2020&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;9016661166&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;761122&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;15-Sep-2020&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;6724980729&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;865110&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;25-Jun-2020&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My challenge is finding a query/code to automate this search without having to write a new search query for each of my provider IDs, Facility IDs, and dates.&lt;/P&gt;&lt;P&gt;I used a code/query below and got results for the first facility ID and provider ID, but do not want to have to repeat for all the provider IDs and facility IDs I have.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%LET sql=%STR(CREATE TABLE &amp;amp;myschema..test AS&lt;BR /&gt;SELECT i.bene_clm_acnt_num,&lt;BR /&gt;i.clm_atndg_physn_npi_num,&lt;BR /&gt;i.clm_atndg_physn_srnm_name,&lt;BR /&gt;i.prvdr_num,&lt;BR /&gt;&lt;BR /&gt;i.bene_race_cd,&lt;BR /&gt;&lt;BR /&gt;i.clm_from_dt AS clm_from_dt1,&lt;BR /&gt;&lt;BR /&gt;i.bene_rsdnc_ssa_std_state_cd,&lt;BR /&gt;i.bene_birth_dt,&lt;BR /&gt;i.clm_pmt_amt,&lt;BR /&gt;i.org_npi_num,&lt;BR /&gt;i.clm_from_dt as clm_admsn_dt,&lt;BR /&gt;i.clm_thru_dt as discharge_dt,&lt;BR /&gt;i.mbi_id,&lt;BR /&gt;b.first_name,&lt;BR /&gt;b.last_name,&lt;BR /&gt;b.claim_account_number,&lt;BR /&gt;b.beneficiary_identification_code as BeneHICN&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;FROM nch_part_a.ipsn_header i&lt;BR /&gt;join beneficiary_data.beneficiary_status b on b.claim_account_number =i.bene_clm_acnt_num&lt;BR /&gt;WHERE&lt;BR /&gt;fac-id ='190002' and&lt;BR /&gt;prov_id = '1265622732'&lt;BR /&gt;and DATE_FORMAT(clm_thru_dt, 'yyyyMMdd') &amp;gt;= '20180801'&lt;BR /&gt;and DATE_FORMAT(clm_thru_dt, 'yyyyMMdd') &amp;lt;= '20200801'&lt;BR /&gt;);&lt;/P&gt;&lt;P&gt;I will grateful if someone can help me with this.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 19:25:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Querying-SQL-database-using-SAS/m-p/761489#M240981</guid>
      <dc:creator>Rahim9</dc:creator>
      <dc:date>2021-08-13T19:25:39Z</dc:date>
    </item>
    <item>
      <title>Re: Querying SQL database using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Querying-SQL-database-using-SAS/m-p/761728#M241073</link>
      <description>&lt;P&gt;I'm unsure I understand. Have you tried the in() operator?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;WHERE fac_id  IN ('190002' , '190001')
  and prov_id IN ('1265622732', '1265622730')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 03:47:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Querying-SQL-database-using-SAS/m-p/761728#M241073</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-08-16T03:47:14Z</dc:date>
    </item>
  </channel>
</rss>

