<?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: Join tables from different libraries in sas sql procedures in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables-from-different-libraries-in-sas-sql-procedures/m-p/635065#M78048</link>
    <description>&lt;P&gt;Thanks for shared information!&lt;/P&gt;</description>
    <pubDate>Thu, 26 Mar 2020 15:51:26 GMT</pubDate>
    <dc:creator>xliu1</dc:creator>
    <dc:date>2020-03-26T15:51:26Z</dc:date>
    <item>
      <title>Join tables from different libraries in sas sql procedures</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables-from-different-libraries-in-sas-sql-procedures/m-p/634474#M77968</link>
      <description>&lt;P&gt;I need to join multiple tables from different libraries in sas. here is the code I use to connect three tables. SID and Prod are two different libraries in SAS. The problem is when I click on run, the software stops working. The software works fine when I run programs that have tables from the same library. I want to make sure the way I join tables are correct. I use different login credentials for these two libraries.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt; from SID.SID_Person_Demo P
        inner join SID.SID_Enrollments_All_Vw E on P.UID=E.UID
        left join Prod.Spraddr A on E.OASIS_PIDM=A.SPRADDR_PIDM&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2020 16:12:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-tables-from-different-libraries-in-sas-sql-procedures/m-p/634474#M77968</guid>
      <dc:creator>xliu1</dc:creator>
      <dc:date>2020-03-24T16:12:45Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables from different libraries in sas sql procedures</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables-from-different-libraries-in-sas-sql-procedures/m-p/634477#M77970</link>
      <description>Are these non SAS tables,  I.e in Oracle or some other database?   If so, you are doing what is called a cross-sever join.   You may consider using pass-through to join  the tables in the background database server.   In that case,  you would need that one of the Oracle schemes be granted  access to the other.   &lt;BR /&gt;</description>
      <pubDate>Tue, 24 Mar 2020 16:21:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-tables-from-different-libraries-in-sas-sql-procedures/m-p/634477#M77970</guid>
      <dc:creator>DavePrinsloo</dc:creator>
      <dc:date>2020-03-24T16:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables from different libraries in sas sql procedures</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables-from-different-libraries-in-sas-sql-procedures/m-p/634482#M77971</link>
      <description>It's hard to say without seeing the rest of your query. Are you using SQL Pass-through, RSUBMIT, Regular SQL, FEDSQL????&lt;BR /&gt;&lt;BR /&gt;Either way, assuming you've set up the libnames with two libname statements and are using regular PROC SQL, my guess is these are large tables. When SAS is joining these tables behind the scenes, it actually has to go download all the data first. This can be quite cumbersome from a timing perspective so often I'll filter my data sets to just the minimum set of  variables and rows, extract them first and then join within SAS. Ultimately it depends on how often your'e doing this and what type of performance you need.</description>
      <pubDate>Tue, 24 Mar 2020 16:45:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-tables-from-different-libraries-in-sas-sql-procedures/m-p/634482#M77971</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-03-24T16:45:31Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables from different libraries in sas sql procedures</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables-from-different-libraries-in-sas-sql-procedures/m-p/634511#M77972</link>
      <description>&lt;P&gt;Thanks for your prompt response. I use regular sql procedure in sas. I get your points. These are very large tables that have 50000 rows. I will try your way of connecting those datasets. Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2020 17:33:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-tables-from-different-libraries-in-sas-sql-procedures/m-p/634511#M77972</guid>
      <dc:creator>xliu1</dc:creator>
      <dc:date>2020-03-24T17:33:24Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables from different libraries in sas sql procedures</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables-from-different-libraries-in-sas-sql-procedures/m-p/634513#M77973</link>
      <description>&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2020 17:41:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-tables-from-different-libraries-in-sas-sql-procedures/m-p/634513#M77973</guid>
      <dc:creator>xliu1</dc:creator>
      <dc:date>2020-03-24T17:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables from different libraries in sas sql procedures</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables-from-different-libraries-in-sas-sql-procedures/m-p/634522#M77974</link>
      <description>50,000 rows wouldn't be considered large in SAS tables at all. If you were doing tens of million is when I'd get concerned. If its only 50,000 rows you should be fine.</description>
      <pubDate>Tue, 24 Mar 2020 18:01:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-tables-from-different-libraries-in-sas-sql-procedures/m-p/634522#M77974</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-03-24T18:01:57Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables from different libraries in sas sql procedures</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables-from-different-libraries-in-sas-sql-procedures/m-p/634528#M77975</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql outobs=500;
    create table NPSAS20_Enrollment as
	    select distinct P.UID label='Student ID',
         P.NAME_FIRST label='First Name',
		 P.NAME_MI label='Middle Name',
		 P.NAME_LAST label='Last Name',
		 P.SUFFIX label='Name suffix',
		 P.GENDER label='Sex',
         case when E.Military_Status in ('A','N') then 2
		      when E.Military_Status in ('E','R','V','Y') then 1
			  when E.Military_Status = 'D' then 0
			  when E.Military_Status is null then 0
		      else -1 end label='Veteran or Active Duty Military status',
		 case when E.DUAL_ENROLL_IND='N' then 0
              when E.DUAL_ENROLL_IND in ('O','P','S','V') then 1
              else -1 end as Dual label='Dual enrollment indicator',
		 substr(P.BIRTH_YYYYMM_DT, 5, 2) as MonthofBirth label='Date of birth month',
		 substr(P.BIRTH_YYYYMM_DT, 7, 2) as DateofBirth label='Date of birth day',
		 substr(P.BIRTH_YYYYMM_DT, 1, 4) as YearofBirth label='Date of birth year',
		 case when P.HISPANIC_FLG = 'Y' then 1
		      when P.HISPANIC_FLG = 'N' then 0
			  else -1 end as Ethnicty label='Ethnicity',
         case when P.WHITE_FLG = 'Y' then 1
              when P.WHITE_FLG = 'N' then 0
			  else -1 end as White label='Race:White',
		 case when P.BLACK_AFRICAN_AM_FLG = 'Y' then 1
              when P.BLACK_AFRICAN_AM_FLG = 'N' then 0
			  else -1 end as Black label='Race:Black or African American',
         case when P.ASIAN_FLG = 'Y' then 1
              when P.ASIAN_FLG = 'N' then 0
			  else -1 end as Asian label='Race:Asian',
         case when P.AM_IND_ALASKAN_FLG = 'Y' then 1
              when P.AM_IND_ALASKAN_FLG = 'N' then 0
			  else -1 end as AmericanIndian label='Race:American Indian or Alaska Native',
         case when P.NAT_HAWAII_PAC_IS_FLG = 'Y' then 1
              when P.NAT_HAWAII_PAC_IS_FLG = 'N' then 0
			  else -1 end as NativeHawaiian label='Race:Native Hawaiian or Pacific Islander',
	     case when A.SPRADDR_ATYP_CODE = 'PM' then A.SPRADDR_STREET_LINE1 else '' end as Addressline1 label='Permanent address 1' 

        from SID.SID_Person_Demo P
        inner join SID.SID_Enrollments_All_Vw E on P.UID=E.UID
        left join Prod.Spraddr A on E.OASIS_PIDM=A.SPRADDR_PIDM

Where E.TERMID IN ('201905','201908','202001')
          and E.BENCH='B'; 
               
		
	select * from NPSAS20_Enrollment;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;Here are my codes. Three tables are used. The program works fine until I joined Prod.Spraddr into the program.&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2020 18:32:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-tables-from-different-libraries-in-sas-sql-procedures/m-p/634528#M77975</guid>
      <dc:creator>xliu1</dc:creator>
      <dc:date>2020-03-24T18:32:31Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables from different libraries in sas sql procedures</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables-from-different-libraries-in-sas-sql-procedures/m-p/634598#M77980</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when E.Military_Status in ('A','N') then 2
		      when E.Military_Status in ('E','R','V','Y') then 1
			  when E.Military_Status = 'D' then 0
			  when E.Military_Status is null then 0
		      else -1 end label='Veteran or Active Duty Military status',&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Missing an as there?&lt;/P&gt;
&lt;P&gt;No variable name?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, if you're recoding a bunch of Y/N to a consistent code, ie 0/1/-1 then I would suggest using an informat instead. It's cleaner and you only have to change it in one place. I'd also recommend leaving the -1 as missing, that way you can do summary stats on the column without any issues. If you have multiple missing values, use a special missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For testing purposes, I'd split the join and data extract from the new variable creation to ensure that I knew which was taking time and worth making more efficient. My suggestions above are faster for you as a programmer but likely won't affect your run time that significantly except the informat portion.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2020 22:02:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-tables-from-different-libraries-in-sas-sql-procedures/m-p/634598#M77980</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-03-24T22:02:49Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables from different libraries in sas sql procedures</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables-from-different-libraries-in-sas-sql-procedures/m-p/634768#M78012</link>
      <description>&lt;P&gt;Thanks for your response. I am not very familiar with informat coding. Would you please send me an example?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Also I want to clarify the recommendation you mentioned in your previous response about "extract them first and then join within SAS". Do you mean I create tables using the same library, and then use "data merge" function to combine them later? Thanks for your help!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2020 14:17:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-tables-from-different-libraries-in-sas-sql-procedures/m-p/634768#M78012</guid>
      <dc:creator>xliu1</dc:creator>
      <dc:date>2020-03-25T14:17:27Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables from different libraries in sas sql procedures</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables-from-different-libraries-in-sas-sql-procedures/m-p/634907#M78031</link>
      <description>&lt;P&gt;Here's a paper that covers informats and their usages:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.lexjansen.com/pharmasug/2005/posters/po06.pdf" target="_blank"&gt;https://www.lexjansen.com/pharmasug/2005/posters/po06.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For data extracts, I mean I'd pull down parts of each table manually via a sql or data step, filtering out rows and columns as much as possible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And then do a SQL merge after, you can use SQL on your SAS data sets or a data step merge, they're usually equivalent approaches.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2020 21:51:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-tables-from-different-libraries-in-sas-sql-procedures/m-p/634907#M78031</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-03-25T21:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables from different libraries in sas sql procedures</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables-from-different-libraries-in-sas-sql-procedures/m-p/635001#M78037</link>
      <description>On the concept of "extract them first":  The simplest way is to use proc copy to copy the entire tables.   &lt;BR /&gt;You would want to do that with SID.SID_Person_Demo and Prod.Spraddr.&lt;BR /&gt;Then use a data step or proc sql to copy the data from SID.SID_Enrollments_All_Vw &lt;BR /&gt;with Where TERMID IN ('201905','201908','202001')  and BENCH='B'; &lt;BR /&gt;&lt;BR /&gt;Since all the data is now in SAS, the join should be fast.&lt;BR /&gt;</description>
      <pubDate>Thu, 26 Mar 2020 10:58:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-tables-from-different-libraries-in-sas-sql-procedures/m-p/635001#M78037</guid>
      <dc:creator>DavePrinsloo</dc:creator>
      <dc:date>2020-03-26T10:58:41Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables from different libraries in sas sql procedures</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables-from-different-libraries-in-sas-sql-procedures/m-p/635036#M78046</link>
      <description>&lt;P&gt;Thanks for your response!&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2020 13:15:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-tables-from-different-libraries-in-sas-sql-procedures/m-p/635036#M78046</guid>
      <dc:creator>xliu1</dc:creator>
      <dc:date>2020-03-26T13:15:17Z</dc:date>
    </item>
    <item>
      <title>Re: Join tables from different libraries in sas sql procedures</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Join-tables-from-different-libraries-in-sas-sql-procedures/m-p/635065#M78048</link>
      <description>&lt;P&gt;Thanks for shared information!&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2020 15:51:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Join-tables-from-different-libraries-in-sas-sql-procedures/m-p/635065#M78048</guid>
      <dc:creator>xliu1</dc:creator>
      <dc:date>2020-03-26T15:51:26Z</dc:date>
    </item>
  </channel>
</rss>

