<?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: Proc SQL - Force Missing Data so Left Join will work? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Force-Missing-Data-so-Left-Join-will-work/m-p/501564#M133740</link>
    <description>&lt;P&gt;Apologies for not providing enough information.&amp;nbsp; My initial hope was that there was just something obvious in the code that I was missing and that data would not be necessary.&amp;nbsp; Unfortunately, there isn't a way to just provide a few lines of data for testing and I debated on whether or not to post this because of that dilemma.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway, apologies again for those of you that took time away to view any of this.&amp;nbsp; Please consider this post withdrawn and no replies are necessary.&lt;/P&gt;</description>
    <pubDate>Thu, 04 Oct 2018 16:14:19 GMT</pubDate>
    <dc:creator>shounster</dc:creator>
    <dc:date>2018-10-04T16:14:19Z</dc:date>
    <item>
      <title>Proc SQL - Force Missing Data so Left Join will work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Force-Missing-Data-so-Left-Join-will-work/m-p/501220#M133613</link>
      <description>&lt;P&gt;I'm not 100% sure if this exact issue has been solved, and I apologize before hand if it has. Sometimes finding the right syntax to ask the community eludes me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway, there's a lot going on here.&amp;nbsp; In a nut shell, I am trying to merge similar tables together based on slightly different criteria when building the pre-merge tables.&amp;nbsp; I would like one table (left) to have every instance of an age grouping so when I merge the right table, it doesn't loose records because there wasn't a match.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First table (Right table) is created with the following code:&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table hosp_in as&lt;BR /&gt;select MS_DRG_Code&lt;BR /&gt;,Service_Line_Group&lt;BR /&gt;,Service_Line&lt;BR /&gt;,Sub_Service_Line&lt;BR /&gt;,Payor_Group&lt;BR /&gt;,DISCHARGE_QTRYR&lt;BR /&gt;,Service_Area&lt;BR /&gt;,State_Hospital_ID&lt;BR /&gt;,Hospital_Name&lt;BR /&gt;,age_group_detail&lt;BR /&gt;,sum(Market_In_Migration) as Market_In_Migration&lt;BR /&gt;,sum(Client_In_Market) as Client_In_Market&lt;BR /&gt;,sum(Client_In_Migration) as Client_In_Migration&lt;BR /&gt;from hosp_inx&lt;BR /&gt;group by MS_DRG_Code&lt;BR /&gt;,Service_Line_Group&lt;BR /&gt;,Service_Line&lt;BR /&gt;,Sub_Service_Line&lt;BR /&gt;,Payor_Group&lt;BR /&gt;,DISCHARGE_QTRYR&lt;BR /&gt;,Service_Area&lt;BR /&gt;,State_Hospital_ID&lt;BR /&gt;,Hospital_Name&lt;BR /&gt;,age_group_detail&lt;BR /&gt;having service_Area ^= ''&amp;nbsp;;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This table seems to create correctly and I have been able to match the results using proc summary.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the code for the second table (Left Table):&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE MIG_FINALx AS&lt;BR /&gt;SELECT DISTINCT&lt;BR /&gt;t1.DISCHARGE_QTRYR&lt;BR /&gt;,t1.MS_DRG_Code&lt;BR /&gt;,t1.MS_DRG_Desc&lt;BR /&gt;,t1.Service_Line_Group&lt;BR /&gt;,t1.Service_Line&lt;BR /&gt;,t1.Sub_Service_Line&lt;BR /&gt;,t1.SA as Service_Area&lt;BR /&gt;,t1.Payor_Group&lt;BR /&gt;,t1.state_hospital_id&lt;BR /&gt;,t1.hospital_name&lt;BR /&gt;,t1.age_group_detail&lt;BR /&gt;,(MAX(t1.Contribution_Margin)) FORMAT=dollar16.2 AS Contribution_Margin&lt;BR /&gt;,(SUM(t1.SA_pt)) AS Market_Total&lt;BR /&gt;,(sum(case when SA_pt=1 and compress(upcase(t1.hospital_SA)) ^= compress(upcase(scan(t1.Service_Area,1," ")))&lt;BR /&gt;then 1 else 0 end)) AS Market_Out_Migration&lt;BR /&gt;FROM MIG2 t1&lt;BR /&gt;GROUP BY t1.MS_DRG_Code&lt;BR /&gt;,t1.Service_Line_Group&lt;BR /&gt;,t1.Service_Line&lt;BR /&gt;,t1.Sub_Service_Line&lt;BR /&gt;,t1.Payor_Group&lt;BR /&gt;,t1.DISCHARGE_QTRYR&lt;BR /&gt;,t1.SA&lt;BR /&gt;,t1.state_hospital_id&lt;BR /&gt;,t1.hospital_name&lt;BR /&gt;,t1.age_group_detail&lt;BR /&gt;HAVING Service_Area ^= ''&lt;BR /&gt;;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The second table is doing what it is 'told'; however, the age_group_detail is what is causing problems in the final merge:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table mig_final as&lt;BR /&gt;select t1.DISCHARGE_QTRYR&lt;BR /&gt;,t1.MS_DRG_Code&lt;BR /&gt;,t1.MS_DRG_Desc&lt;BR /&gt;,t1.Service_Line_Group&lt;BR /&gt;,t1.Service_Line&lt;BR /&gt;,t1.Sub_Service_Line&lt;BR /&gt;,t1.Service_Area&lt;BR /&gt;,t1.Payor_Group&lt;BR /&gt;,t1.Contribution_Margin&lt;BR /&gt;,t1.Market_Total&lt;BR /&gt;,t1.Market_Out_Migration&lt;BR /&gt;,t2.Market_In_Migration&lt;BR /&gt;,t2.Client_In_Market&lt;BR /&gt;,t2.Client_In_Migration&lt;BR /&gt;,t1.State_Hospital_ID&lt;BR /&gt;,t1.Hospital_Name&lt;BR /&gt;,t1.age_group_detail&lt;BR /&gt;from mig_finalx t1&lt;BR /&gt;LEFT JOIN HOSP_IN t2&lt;BR /&gt;on compress(upcase(scan(t1.Service_Area,1," "))) =&lt;BR /&gt;compress(upcase(t2.Service_Area))&lt;BR /&gt;and compress(t1.Discharge_QtrYr)=compress(t2.Discharge_QtrYr)&lt;BR /&gt;and compress(t1.MS_DRG_Code) = compress(t2.MS_DRG_Code)&lt;BR /&gt;and compress(t1.Service_Line_Group) =&lt;BR /&gt;compress(t2.Service_Line_Group)&lt;BR /&gt;and compress(t1.Service_Line) = compress(t2.Service_Line)&lt;BR /&gt;and compress(t1.Sub_Service_Line) = compress(t2.Sub_Service_Line)&lt;BR /&gt;and compress(t1.Payor_Group) = compress(t2.Payor_Group)&lt;BR /&gt;and compress(t1.state_hospital_id) =&lt;BR /&gt;compress(t2.state_hospital_id)&lt;BR /&gt;and t1.age_group_detail = t2.age_group_detail&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I create the mig_final table (above), where the age_group_detail isn't 'complete' or missing like the first table, it omits data from the first/right (hosp_in) table.&amp;nbsp; I understand that the left join will keep the records from the left table (mig_finalx).&amp;nbsp; However, a straight join doesn't seem to work either.&amp;nbsp; I know that proc sql handles missing values differently than data steps or procedures in SAS, but I just can't seem to find the right combination.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On this same tangent, I would like to create a proc summary from the sql that creates mig_finalx, but I'm not sure I understand how I can 'convert' the case statement unless I do a data step to create the out_migration variable and then run proc summary.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I might be able to attach data if necessary.&amp;nbsp; Any assistance would be greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 17:34:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Force-Missing-Data-so-Left-Join-will-work/m-p/501220#M133613</guid>
      <dc:creator>shounster</dc:creator>
      <dc:date>2018-10-03T17:34:17Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - Force Missing Data so Left Join will work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Force-Missing-Data-so-Left-Join-will-work/m-p/501297#M133649</link>
      <description>&lt;P&gt;You are not being reasonable here.&lt;/P&gt;
&lt;P&gt;Your queries are long and you provide no data.&lt;/P&gt;
&lt;P&gt;Please spend the time to create a few lines of mock data illustrating your issue and post it, together with expected output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 22:51:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Force-Missing-Data-so-Left-Join-will-work/m-p/501297#M133649</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-10-03T22:51:10Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - Force Missing Data so Left Join will work?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Force-Missing-Data-so-Left-Join-will-work/m-p/501564#M133740</link>
      <description>&lt;P&gt;Apologies for not providing enough information.&amp;nbsp; My initial hope was that there was just something obvious in the code that I was missing and that data would not be necessary.&amp;nbsp; Unfortunately, there isn't a way to just provide a few lines of data for testing and I debated on whether or not to post this because of that dilemma.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway, apologies again for those of you that took time away to view any of this.&amp;nbsp; Please consider this post withdrawn and no replies are necessary.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 16:14:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Force-Missing-Data-so-Left-Join-will-work/m-p/501564#M133740</guid>
      <dc:creator>shounster</dc:creator>
      <dc:date>2018-10-04T16:14:19Z</dc:date>
    </item>
  </channel>
</rss>

