<?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 Running a query from another query in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Running-a-query-from-another-query/m-p/780066#M248510</link>
    <description>&lt;P&gt;Hello all&lt;/P&gt;&lt;P&gt;I ran this query and got my desired dataset:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;PROC SQL;
CREATE TABLE work.patient_cohort AS
SELECT DISTINCT a.mrn
	, a.PatientNM
	, a.dob
	, a.payorNM
	, scan(a.patientnm,1,',') as lastname
	, scan(a.patientnm, 2, ',') as firstname
	, a.SubscriberID as InsuredsIDNumber
	, a.firstDt as cohort_entering_Date
	, a.planID
	, a.PayorID
	,COMPRESS(SubscriberID, '', 'kd') AS EditedInsuredsIDNumber

FROM work.dataPull_2 a 
	INNER JOIN work.cntByMRN b
		ON a.mrn= b.mrn
	WHERE 
	 payorID = 110001
;QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What I want to do now is use the MRN variable that was created in the above code and use them to run the below query so that only the MRN's from the top query is used in the second query:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;PROC SQL;
CREATE TABLE work.patient_race AS
SELECT DISTINCT
	  I.PatientIdentityID as PatientMRN
	  ,py.PayorID
      ,py.PayorNM
	  ,Loc.RevenueLocationNM
	,CASE WHEN PatientRaceDSC = 'ASIAN' THEN 'Asian'
		  WHEN PatientRaceDSC = 'BLACK OR AFRICAN AMERICAN' THEN 'Black or African American'
		  WHEN PatientRaceDSC = 'Hispanic or Latino' THEN 'Hispanic or Latino'
		  WHEN PatientRaceDSC LIKE ('WHITE%') THEN 'White or Caucasian'
		  WHEN PatientRaceDSC = 'American Indian or Alaska Native' THEN 'American Indian or Alaska Native'
		  WHEN PatientRaceDSC = 'Native Hawaiian or Other Pacific Islander' THEN 'Native Hawaiian or Other Pacific Islander'
	 	  WHEN PatientRaceDSC IN ('Declined', 'Unavailable') THEN 'Unknown'
		  WHEN PatientRaceDSC IS NULL THEN 'Unknown'
		  ELSE 'Other' END AS RACE
	, CASE WHEN EthnicGroupDSC in ('Yes Hispanic','Hispanic') THEN 'YES' 
	      ELSE 'NO' END AS HISPANIC_OR_LATINO

FROM fin.HospitalAccount HA 	
LEFT JOIN ref.Location LOC ON HA.DischargeEpicLocationID = LOC.LocationID
LEFT JOIN pat.Race R on HA.PatientID = R.PatientID
LEFT JOIN pat.Patient P on HA.PatientID = P.PatientID
LEFT JOIN fin.HospitalTransaction HT on HA.HospitalAccountID = HT.HospitalAccountID	
LEFT JOIN pat.Identity I on HA.PatientID = I.PatientID
LEFT JOIN ref.Payor PY ON HA.FinancialClassCD = PY.FinancialClassCD

;quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is it possible to do that?&lt;/P&gt;</description>
    <pubDate>Fri, 12 Nov 2021 22:46:30 GMT</pubDate>
    <dc:creator>wheddingsjr</dc:creator>
    <dc:date>2021-11-12T22:46:30Z</dc:date>
    <item>
      <title>Running a query from another query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-a-query-from-another-query/m-p/780066#M248510</link>
      <description>&lt;P&gt;Hello all&lt;/P&gt;&lt;P&gt;I ran this query and got my desired dataset:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;PROC SQL;
CREATE TABLE work.patient_cohort AS
SELECT DISTINCT a.mrn
	, a.PatientNM
	, a.dob
	, a.payorNM
	, scan(a.patientnm,1,',') as lastname
	, scan(a.patientnm, 2, ',') as firstname
	, a.SubscriberID as InsuredsIDNumber
	, a.firstDt as cohort_entering_Date
	, a.planID
	, a.PayorID
	,COMPRESS(SubscriberID, '', 'kd') AS EditedInsuredsIDNumber

FROM work.dataPull_2 a 
	INNER JOIN work.cntByMRN b
		ON a.mrn= b.mrn
	WHERE 
	 payorID = 110001
;QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What I want to do now is use the MRN variable that was created in the above code and use them to run the below query so that only the MRN's from the top query is used in the second query:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;PROC SQL;
CREATE TABLE work.patient_race AS
SELECT DISTINCT
	  I.PatientIdentityID as PatientMRN
	  ,py.PayorID
      ,py.PayorNM
	  ,Loc.RevenueLocationNM
	,CASE WHEN PatientRaceDSC = 'ASIAN' THEN 'Asian'
		  WHEN PatientRaceDSC = 'BLACK OR AFRICAN AMERICAN' THEN 'Black or African American'
		  WHEN PatientRaceDSC = 'Hispanic or Latino' THEN 'Hispanic or Latino'
		  WHEN PatientRaceDSC LIKE ('WHITE%') THEN 'White or Caucasian'
		  WHEN PatientRaceDSC = 'American Indian or Alaska Native' THEN 'American Indian or Alaska Native'
		  WHEN PatientRaceDSC = 'Native Hawaiian or Other Pacific Islander' THEN 'Native Hawaiian or Other Pacific Islander'
	 	  WHEN PatientRaceDSC IN ('Declined', 'Unavailable') THEN 'Unknown'
		  WHEN PatientRaceDSC IS NULL THEN 'Unknown'
		  ELSE 'Other' END AS RACE
	, CASE WHEN EthnicGroupDSC in ('Yes Hispanic','Hispanic') THEN 'YES' 
	      ELSE 'NO' END AS HISPANIC_OR_LATINO

FROM fin.HospitalAccount HA 	
LEFT JOIN ref.Location LOC ON HA.DischargeEpicLocationID = LOC.LocationID
LEFT JOIN pat.Race R on HA.PatientID = R.PatientID
LEFT JOIN pat.Patient P on HA.PatientID = P.PatientID
LEFT JOIN fin.HospitalTransaction HT on HA.HospitalAccountID = HT.HospitalAccountID	
LEFT JOIN pat.Identity I on HA.PatientID = I.PatientID
LEFT JOIN ref.Payor PY ON HA.FinancialClassCD = PY.FinancialClassCD

;quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is it possible to do that?&lt;/P&gt;</description>
      <pubDate>Fri, 12 Nov 2021 22:46:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-a-query-from-another-query/m-p/780066#M248510</guid>
      <dc:creator>wheddingsjr</dc:creator>
      <dc:date>2021-11-12T22:46:30Z</dc:date>
    </item>
    <item>
      <title>Re: Running a query from another query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-a-query-from-another-query/m-p/780074#M248515</link>
      <description>&lt;P&gt;Add in via WHERE or another join.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where i.patientID in  (select distinct mrn from patient_cohort) &lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/114971"&gt;@wheddingsjr&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello all&lt;/P&gt;
&lt;P&gt;I ran this query and got my desired dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;PROC SQL;
CREATE TABLE work.patient_cohort AS
SELECT DISTINCT a.mrn
	, a.PatientNM
	, a.dob
	, a.payorNM
	, scan(a.patientnm,1,',') as lastname
	, scan(a.patientnm, 2, ',') as firstname
	, a.SubscriberID as InsuredsIDNumber
	, a.firstDt as cohort_entering_Date
	, a.planID
	, a.PayorID
	,COMPRESS(SubscriberID, '', 'kd') AS EditedInsuredsIDNumber

FROM work.dataPull_2 a 
	INNER JOIN work.cntByMRN b
		ON a.mrn= b.mrn
	WHERE 
	 payorID = 110001
;QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What I want to do now is use the MRN variable that was created in the above code and use them to run the below query so that only the MRN's from the top query is used in the second query:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;PROC SQL;
CREATE TABLE work.patient_race AS
SELECT DISTINCT
	  I.PatientIdentityID as PatientMRN
	  ,py.PayorID
      ,py.PayorNM
	  ,Loc.RevenueLocationNM
	,CASE WHEN PatientRaceDSC = 'ASIAN' THEN 'Asian'
		  WHEN PatientRaceDSC = 'BLACK OR AFRICAN AMERICAN' THEN 'Black or African American'
		  WHEN PatientRaceDSC = 'Hispanic or Latino' THEN 'Hispanic or Latino'
		  WHEN PatientRaceDSC LIKE ('WHITE%') THEN 'White or Caucasian'
		  WHEN PatientRaceDSC = 'American Indian or Alaska Native' THEN 'American Indian or Alaska Native'
		  WHEN PatientRaceDSC = 'Native Hawaiian or Other Pacific Islander' THEN 'Native Hawaiian or Other Pacific Islander'
	 	  WHEN PatientRaceDSC IN ('Declined', 'Unavailable') THEN 'Unknown'
		  WHEN PatientRaceDSC IS NULL THEN 'Unknown'
		  ELSE 'Other' END AS RACE
	, CASE WHEN EthnicGroupDSC in ('Yes Hispanic','Hispanic') THEN 'YES' 
	      ELSE 'NO' END AS HISPANIC_OR_LATINO

FROM fin.HospitalAccount HA 	
LEFT JOIN ref.Location LOC ON HA.DischargeEpicLocationID = LOC.LocationID
LEFT JOIN pat.Race R on HA.PatientID = R.PatientID
LEFT JOIN pat.Patient P on HA.PatientID = P.PatientID
LEFT JOIN fin.HospitalTransaction HT on HA.HospitalAccountID = HT.HospitalAccountID	
LEFT JOIN pat.Identity I on HA.PatientID = I.PatientID
LEFT JOIN ref.Payor PY ON HA.FinancialClassCD = PY.FinancialClassCD

;quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is it possible to do that?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 Nov 2021 00:35:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-a-query-from-another-query/m-p/780074#M248515</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-11-13T00:35:34Z</dc:date>
    </item>
    <item>
      <title>Re: Running a query from another query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-a-query-from-another-query/m-p/780085#M248523</link>
      <description>&lt;P&gt;A join is usually faster than a&amp;nbsp; &amp;nbsp;&lt;FONT face="courier new,courier"&gt; in (select from ... )&amp;nbsp;&lt;/FONT&gt; clause&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Nov 2021 04:36:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-a-query-from-another-query/m-p/780085#M248523</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-11-16T04:36:36Z</dc:date>
    </item>
    <item>
      <title>Re: Running a query from another query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-a-query-from-another-query/m-p/780088#M248526</link>
      <description>Yup but not sure of the structure of the other tables and if they have multiple IDs and then it would likely be a right/inner join instead and no way to test it. The solution posted will work and is easy to understand.</description>
      <pubDate>Sat, 13 Nov 2021 03:55:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-a-query-from-another-query/m-p/780088#M248526</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-11-13T03:55:18Z</dc:date>
    </item>
    <item>
      <title>Re: Running a query from another query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-a-query-from-another-query/m-p/780166#M248567</link>
      <description>&lt;P&gt;I'd use&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; join (select unique .... from TABLE2)&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;but that's me.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Nov 2021 04:10:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-a-query-from-another-query/m-p/780166#M248567</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-11-15T04:10:22Z</dc:date>
    </item>
  </channel>
</rss>

