<?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 Check for a variable when a joining the table inside proc sql ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Check-for-a-variable-when-a-joining-the-table-inside-proc-sql/m-p/377370#M276721</link>
    <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;I am posting this question with reference to the &lt;A href="https://communities.sas.com/t5/General-SAS-Programming/Check-the-presence-of-variable-when-a-join-the-table-from-within/m-p/377122#M48264" target="_self"&gt;QUESTION&lt;/A&gt;&amp;nbsp;that I have posted before. I am trying to solve a more complicated scenario this time. As said&amp;nbsp;&lt;SPAN&gt;I am dealing with large number of different structured xmls, So everytime whenever I create my&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;final_table&lt;/STRONG&gt;&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;I would like to know if there is a way that I can check the variable is present or not before doing the join inside the proc sql.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here this code works when I have any of the variables [a.x1 or a.y1 or a.z1] for dynamicSelectVar1 and [a.x2 or a.y2] for&amp;nbsp;&lt;SPAN&gt;dynamicSelectVar2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;But if I dont have any of the variables this gives me the &amp;nbsp;error that I have shown in my original post. For instance if I dont have any variables in&amp;nbsp;&lt;SPAN&gt;dynamicSelectVar2 then the error is:&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class="sasError"&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;ERROR: Column x2 could not be found in the table/view identified with the correlation name a.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;ERROR: Column y2 could not be found in the table/view identified with the correlation name a.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;P&gt;So can you help on how to handle this exception&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Following is my piece of code&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
SELECT cats('a.', name) INTO :dynamicSelectVar1 separated by ' '
FROM sashelp.vcolumn
WHERE libname = 'WORK' and
               memname = 'FINAL_OUTPUT' and
               name  in  ('x1','y1','z1');
quit;
%put &amp;amp;dynamicSelectVar1;

proc sql noprint;
SELECT cats('a.', name) INTO :dynamicSelectVar2 separated by ' '
FROM sashelp.vcolumn
WHERE libname = 'WORK' and
               memname = 'FINAL_OUTPUT' and
               name  in  ('x2','y2');
quit;
%put &amp;amp;dynamicSelectVar2;


proc sql ;
	create table final_table  AS
		select
			 a.customer
			,a.year
			,&amp;amp;dynamicSelectVar1
			,b.*
                        ,&amp;amp;dynamicSelectVar2
			,c.*
			
	from work.final_output as a 
        inner join prod.scores as b on a.id = b.id
	inner join prod.city as c on a.business_id=c.id
	
quit;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 19 Jul 2017 15:00:45 GMT</pubDate>
    <dc:creator>jjames1</dc:creator>
    <dc:date>2017-07-19T15:00:45Z</dc:date>
    <item>
      <title>Check for a variable when a joining the table inside proc sql ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-for-a-variable-when-a-joining-the-table-inside-proc-sql/m-p/377370#M276721</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;I am posting this question with reference to the &lt;A href="https://communities.sas.com/t5/General-SAS-Programming/Check-the-presence-of-variable-when-a-join-the-table-from-within/m-p/377122#M48264" target="_self"&gt;QUESTION&lt;/A&gt;&amp;nbsp;that I have posted before. I am trying to solve a more complicated scenario this time. As said&amp;nbsp;&lt;SPAN&gt;I am dealing with large number of different structured xmls, So everytime whenever I create my&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;final_table&lt;/STRONG&gt;&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;I would like to know if there is a way that I can check the variable is present or not before doing the join inside the proc sql.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here this code works when I have any of the variables [a.x1 or a.y1 or a.z1] for dynamicSelectVar1 and [a.x2 or a.y2] for&amp;nbsp;&lt;SPAN&gt;dynamicSelectVar2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;But if I dont have any of the variables this gives me the &amp;nbsp;error that I have shown in my original post. For instance if I dont have any variables in&amp;nbsp;&lt;SPAN&gt;dynamicSelectVar2 then the error is:&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class="sasError"&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;ERROR: Column x2 could not be found in the table/view identified with the correlation name a.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;ERROR: Column y2 could not be found in the table/view identified with the correlation name a.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;P&gt;So can you help on how to handle this exception&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Following is my piece of code&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
SELECT cats('a.', name) INTO :dynamicSelectVar1 separated by ' '
FROM sashelp.vcolumn
WHERE libname = 'WORK' and
               memname = 'FINAL_OUTPUT' and
               name  in  ('x1','y1','z1');
quit;
%put &amp;amp;dynamicSelectVar1;

proc sql noprint;
SELECT cats('a.', name) INTO :dynamicSelectVar2 separated by ' '
FROM sashelp.vcolumn
WHERE libname = 'WORK' and
               memname = 'FINAL_OUTPUT' and
               name  in  ('x2','y2');
quit;
%put &amp;amp;dynamicSelectVar2;


proc sql ;
	create table final_table  AS
		select
			 a.customer
			,a.year
			,&amp;amp;dynamicSelectVar1
			,b.*
                        ,&amp;amp;dynamicSelectVar2
			,c.*
			
	from work.final_output as a 
        inner join prod.scores as b on a.id = b.id
	inner join prod.city as c on a.business_id=c.id
	
quit;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jul 2017 15:00:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-for-a-variable-when-a-joining-the-table-inside-proc-sql/m-p/377370#M276721</guid>
      <dc:creator>jjames1</dc:creator>
      <dc:date>2017-07-19T15:00:45Z</dc:date>
    </item>
    <item>
      <title>Re: Check for a variable when a joining the table inside proc sql ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-for-a-variable-when-a-joining-the-table-inside-proc-sql/m-p/377390#M276722</link>
      <description>&lt;P&gt;Look at what happens if all your variables are present.&amp;nbsp; In the middle of the SELECT statement, SAS would see:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;,a.year&lt;/P&gt;
&lt;P&gt;,x1 y1 z1&lt;/P&gt;
&lt;P&gt;,b.*&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The correct syntax for SQL is probably this instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;,a.year&lt;/P&gt;
&lt;P&gt;,x1,y1,z1&lt;/P&gt;
&lt;P&gt;,b.*&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To make that happen change your separator in both places:&amp;nbsp; SEPARATED BY&amp;nbsp; ','&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jul 2017 15:25:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-for-a-variable-when-a-joining-the-table-inside-proc-sql/m-p/377390#M276722</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-19T15:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: Check for a variable when a joining the table inside proc sql ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-for-a-variable-when-a-joining-the-table-inside-proc-sql/m-p/377619#M276723</link>
      <description>&lt;P&gt;Also the second,&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token statement"&gt;SELECT&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;cats&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'a.'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; name&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;I&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;should be&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token statement"&gt;SELECT&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;cats&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'b.'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; name&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;I&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jul 2017 22:37:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-for-a-variable-when-a-joining-the-table-inside-proc-sql/m-p/377619#M276723</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-07-19T22:37:56Z</dc:date>
    </item>
  </channel>
</rss>

