<?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: Apparent symbolic reference not resolved in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Missing-functions-inside-a-proc-sql-case-statement-is-failing/m-p/398848#M96509</link>
    <description>&lt;P&gt;I think you just need to make it global before your sql&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%global &lt;FONT face="Courier New"&gt;TransposedColumnsF;&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 26 Sep 2017 15:53:59 GMT</pubDate>
    <dc:creator>FredrikE</dc:creator>
    <dc:date>2017-09-26T15:53:59Z</dc:date>
    <item>
      <title>Missing functions inside a proc sql case statement is failing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Missing-functions-inside-a-proc-sql-case-statement-is-failing/m-p/398846#M96507</link>
      <description>&lt;P&gt;I have a variable that is missing because are no rows that meet the criteria. I need to put a check in place so if the variable is missing, my code does not fail. here is what I have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;noprint&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; name&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;into&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; :TransposedColumnsF &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;separated by &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;','&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; dictionary.columns&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; libname=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'EGTASK'&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;and&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; memname =&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'TRNSTRANSPOSEDFSERIES_MEMBER'&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;AND&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; NAME &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;LIKE&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="3"&gt;'Column%'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;/* transposedColumnF should not return anything*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;/* then I have a case statement to that my query does not fail when the variable does not have any values*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;CREATE&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;TABLE&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; EGTASK.MyNewTable &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;AS&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;SELECT&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;case&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;when&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; missing(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"&amp;amp;TransposedColumnsF."&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="3"&gt;''&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;else&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (CATX(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;","&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&amp;amp;TransposedColumnsF))LABEL=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"Disrupted Drugs"&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;end&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;AS&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="3"&gt;'Disrupted Drugs'n&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;FROM&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; EGTASK.SomeOtherTable t1; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;quit;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;/* I get the following error: "ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string....." &amp;nbsp;The code does not fail if &amp;amp;&lt;FONT color="#800080" face="Courier New"&gt;TransposedColumnsF&lt;/FONT&gt; actually gets a value*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2017 15:55:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Missing-functions-inside-a-proc-sql-case-statement-is-failing/m-p/398846#M96507</guid>
      <dc:creator>spastrana</dc:creator>
      <dc:date>2017-09-26T15:55:02Z</dc:date>
    </item>
    <item>
      <title>Re: Apparent symbolic reference not resolved</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Missing-functions-inside-a-proc-sql-case-statement-is-failing/m-p/398848#M96509</link>
      <description>&lt;P&gt;I think you just need to make it global before your sql&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%global &lt;FONT face="Courier New"&gt;TransposedColumnsF;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2017 15:53:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Missing-functions-inside-a-proc-sql-case-statement-is-failing/m-p/398848#M96509</guid>
      <dc:creator>FredrikE</dc:creator>
      <dc:date>2017-09-26T15:53:59Z</dc:date>
    </item>
    <item>
      <title>Re: Apparent symbolic reference not resolved</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Missing-functions-inside-a-proc-sql-case-statement-is-failing/m-p/398849#M96510</link>
      <description>&lt;P&gt;Hi Federik, thank you for your reply. it still fails&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2017 15:58:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Missing-functions-inside-a-proc-sql-case-statement-is-failing/m-p/398849#M96510</guid>
      <dc:creator>spastrana</dc:creator>
      <dc:date>2017-09-26T15:58:30Z</dc:date>
    </item>
    <item>
      <title>Re: Missing functions inside a proc sql case statement is failing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Missing-functions-inside-a-proc-sql-case-statement-is-failing/m-p/398851#M96511</link>
      <description>&lt;P&gt;What value would you want the variable &lt;FONT color="#800080" face="Courier New" size="3"&gt;&amp;amp;TransposedColumnsF &lt;/FONT&gt;to have when it is missing in the SQL part?&lt;/P&gt;
&lt;P&gt;Use a %let statement before the SQL to assign that value&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let &lt;FONT color="#800080" face="Courier New"&gt;TransposedColumnsF = Text when missing;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;proc sql noprint;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&amp;nbsp;...&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;quit;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;If the SQL is successful it will overwrite the value into the macro variable. If not the preset remains.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2017 16:00:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Missing-functions-inside-a-proc-sql-case-statement-is-failing/m-p/398851#M96511</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-09-26T16:00:06Z</dc:date>
    </item>
    <item>
      <title>Re: Missing functions inside a proc sql case statement is failing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Missing-functions-inside-a-proc-sql-case-statement-is-failing/m-p/398852#M96512</link>
      <description>&lt;P&gt;Actually it looks like you have forgotten some quotation....:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;CATX(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;","&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&amp;amp;TransposedColumnsF))&lt;/FONT&gt; should be &lt;FONT face="Courier New"&gt;CATX(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;","&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,"&amp;amp;TransposedColumnsF"))&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2017 16:01:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Missing-functions-inside-a-proc-sql-case-statement-is-failing/m-p/398852#M96512</guid>
      <dc:creator>FredrikE</dc:creator>
      <dc:date>2017-09-26T16:01:57Z</dc:date>
    </item>
    <item>
      <title>Re: Apparent symbolic reference not resolved</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Missing-functions-inside-a-proc-sql-case-statement-is-failing/m-p/398855#M96514</link>
      <description>&lt;P&gt;Try just adding a %LET statement before your SELECT statement so that you insure the macro variable is created even when there are no matches.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
%let TransposedColumnsF=;
select name
  into :TransposedColumnsF separated by ','
  from dictionary.columns
  where libname='EGTASK'
    and memname ='TRNSTRANSPOSEDFSERIES_MEMBER'
    AND NAME LIKE 'Column%'
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You also need to make sure that you are generating proper syntax for the CATX() command when there are no variables selected.&lt;/P&gt;
&lt;P&gt;If you are not in a macro (and so cannot use %IF statement) you could use the IFC() funtion to conditionally generate some code.&lt;/P&gt;
&lt;P&gt;So I think this is what you intended your CASE statement to do but there was no need for a CASE statement since it was not based on anything that changed per observation in the table.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;CREATE TABLE EGTASK.MyNewTable AS
  SELECT %sysfunc(ifc(&amp;amp;sqlobs&amp;gt;0,CATX(",",&amp;amp;TransposedColumnsF),' '))
    AS 'Disrupted Drugs'n LENGTH=200 LABEL="Disrupted Drugs" 
  FROM EGTASK.SomeOtherTable t1
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2017 16:09:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Missing-functions-inside-a-proc-sql-case-statement-is-failing/m-p/398855#M96514</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-26T16:09:51Z</dc:date>
    </item>
    <item>
      <title>Re: Missing functions inside a proc sql case statement is failing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Missing-functions-inside-a-proc-sql-case-statement-is-failing/m-p/398858#M96516</link>
      <description>&lt;P&gt;thank you, that works!&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2017 16:15:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Missing-functions-inside-a-proc-sql-case-statement-is-failing/m-p/398858#M96516</guid>
      <dc:creator>spastrana</dc:creator>
      <dc:date>2017-09-26T16:15:30Z</dc:date>
    </item>
    <item>
      <title>Re: Apparent symbolic reference not resolved</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Missing-functions-inside-a-proc-sql-case-statement-is-failing/m-p/398859#M96517</link>
      <description>&lt;P&gt;Thank you Tom!&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2017 16:17:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Missing-functions-inside-a-proc-sql-case-statement-is-failing/m-p/398859#M96517</guid>
      <dc:creator>spastrana</dc:creator>
      <dc:date>2017-09-26T16:17:01Z</dc:date>
    </item>
    <item>
      <title>Re: Missing functions inside a proc sql case statement is failing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Missing-functions-inside-a-proc-sql-case-statement-is-failing/m-p/398861#M96519</link>
      <description>&lt;P&gt;When you run a Proc SQL select into SAS will not create a macro variable if does not find any matching rows e.g.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;63         proc sql;
 64         select name into :mynames
 65         separated by ','
 66         from sashelp.class
 67         where name="Colin";
 NOTE: No rows were selected.
 68         quit;
 NOTE: PROCEDURE SQL used (Total process time):
       real time           0.01 seconds
       cpu time            0.02 seconds
       
 
 69         
 70         %put &amp;amp;mynames;
 WARNING: Apparent symbolic reference MYNAMES not resolved.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This means that the macro variable will not resolve to missing because it doesn't exist. You can use the suggestion from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13827"&gt;@FredrikE&lt;/a&gt;&amp;nbsp;to create a default value beforehand which may be the best way to handle this scenario. Interestingly I believe the bahaviour of Proc SQL in this regard changed in SAS v 9.2 or 9.3 - before then SAS would create an empty macro variable which is why you may see something like this work in old code on the web...&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2017 16:20:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Missing-functions-inside-a-proc-sql-case-statement-is-failing/m-p/398861#M96519</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2017-09-26T16:20:08Z</dc:date>
    </item>
    <item>
      <title>Re: Missing functions inside a proc sql case statement is failing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Missing-functions-inside-a-proc-sql-case-statement-is-failing/m-p/398866#M96523</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32246"&gt;@ChrisBrooks&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Interestingly I believe the bahaviour of Proc SQL in this regard changed in SAS v 9.2 or 9.3 - before then SAS would create an empty macro variable which is why you may see something like this work in old code on the web...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Nope. It has always worked this way. There are other ways than using a %LET to insure that the macro variable exists. You could use a %GLOBAL or %LOCAL statement to define the macro variable. &amp;nbsp;Note that when using %LOCAL statement insdie of macro it works almost like using %let to initialize to empty since by default a new macro variable has no content and local macro variables are not remembered across mutliple calls. &amp;nbsp;But a %GLOBAL statment will not re-initalize a macro variable that already exists and a global macro vairable will keep its value until reset or deleted.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2017 16:29:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Missing-functions-inside-a-proc-sql-case-statement-is-failing/m-p/398866#M96523</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-26T16:29:31Z</dc:date>
    </item>
  </channel>
</rss>

