<?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: I want to calculate Variable label only when Variable is not null. in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/I-want-to-calculate-Variable-label-only-when-Variable-is-not/m-p/572829#M75353</link>
    <description>&lt;P&gt;Thank you Tom!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried it and it is working form me &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 11 Jul 2019 16:38:36 GMT</pubDate>
    <dc:creator>sas_clin_usr</dc:creator>
    <dc:date>2019-07-11T16:38:36Z</dc:date>
    <item>
      <title>I want to calculate Variable label only when Variable is not null.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/I-want-to-calculate-Variable-label-only-when-Variable-is-not/m-p/572765#M75345</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to calculate Variable label only when Variable is not null. I am trying to create a User Defined function as below but I am getting compilation error saying:&amp;nbsp;&amp;nbsp;&lt;FONT size="1 2 3 4 5 6 7" color="#FF0000"&gt;ERROR: The VLABEL function is only valid in the DATA step. User defined libraries will be searched for a definition of this&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7" color="#FF0000"&gt;function.&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC FCMP OUTLIB = work.usrfunc.label;
&amp;nbsp; &amp;nbsp;FUNCTION varlbl(var);
&amp;nbsp; &amp;nbsp; &amp;nbsp; IF NOT MISSING (var) THEN RETURN (VLABEL(var));
&amp;nbsp; &amp;nbsp;ENDSUB;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using %SYSFUNC as below but I got another error:&amp;nbsp;&lt;FONT size="1 2 3 4 5 6 7" color="#FF0000"&gt;ERROR: The function VLABEL referenced by %SYSFUNC, %QSYSFUNC, or %SYSCALL cannot be used within the MACRO function/call-routine&amp;nbsp;&lt;/FONT&gt;&lt;FONT size="1 2 3 4 5 6 7" color="#FF0000"&gt;interfaces.&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC FCMP OUTLIB = work.usrfunc.label;
&amp;nbsp; &amp;nbsp;FUNCTION varlbl(var);
&amp;nbsp; &amp;nbsp; &amp;nbsp; IF NOT MISSING (var) THEN RETURN (%SYSFUNC(VLABEL(var)));
&amp;nbsp; &amp;nbsp;ENDSUB;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is there nay way to resolve the above errors to make this program work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 14:41:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/I-want-to-calculate-Variable-label-only-when-Variable-is-not/m-p/572765#M75345</guid>
      <dc:creator>sas_clin_usr</dc:creator>
      <dc:date>2019-07-11T14:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: I want to calculate Variable label only when Variable is not null.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/I-want-to-calculate-Variable-label-only-when-Variable-is-not/m-p/572777#M75346</link>
      <description>&lt;P&gt;What possible value would there be in such a function?&lt;/P&gt;
&lt;P&gt;Just use normal SAS code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;IFC(NOT MISSING (var),VLABEL(var),' ')&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Jul 2019 15:08:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/I-want-to-calculate-Variable-label-only-when-Variable-is-not/m-p/572777#M75346</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-11T15:08:27Z</dc:date>
    </item>
    <item>
      <title>Re: I want to calculate Variable label only when Variable is not null.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/I-want-to-calculate-Variable-label-only-when-Variable-is-not/m-p/572780#M75347</link>
      <description>&lt;P&gt;What do you mean when a variable is null? Is that when all values in that variable are missing?&lt;/P&gt;
&lt;P&gt;Or if a single value is missing?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you show what you have and what you need we can likely help you better, I have a strong suspicion this is an xy problem.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://xyproblem.info/" target="_blank"&gt;http://xyproblem.info/&lt;/A&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281244"&gt;@sas_clin_usr&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to calculate Variable label only when Variable is not null. I am trying to create a User Defined function as below but I am getting compilation error saying:&amp;nbsp;&amp;nbsp;&lt;FONT size="1 2 3 4 5 6 7" color="#FF0000"&gt;ERROR: The VLABEL function is only valid in the DATA step. User defined libraries will be searched for a definition of this&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7" color="#FF0000"&gt;function.&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC FCMP OUTLIB = work.usrfunc.label;
&amp;nbsp; &amp;nbsp;FUNCTION varlbl(var);
&amp;nbsp; &amp;nbsp; &amp;nbsp; IF NOT MISSING (var) THEN RETURN (VLABEL(var));
&amp;nbsp; &amp;nbsp;ENDSUB;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried using %SYSFUNC as below but I got another error:&amp;nbsp;&lt;FONT size="1 2 3 4 5 6 7" color="#FF0000"&gt;ERROR: The function VLABEL referenced by %SYSFUNC, %QSYSFUNC, or %SYSCALL cannot be used within the MACRO function/call-routine&amp;nbsp;&lt;/FONT&gt;&lt;FONT size="1 2 3 4 5 6 7" color="#FF0000"&gt;interfaces.&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC FCMP OUTLIB = work.usrfunc.label;
&amp;nbsp; &amp;nbsp;FUNCTION varlbl(var);
&amp;nbsp; &amp;nbsp; &amp;nbsp; IF NOT MISSING (var) THEN RETURN (%SYSFUNC(VLABEL(var)));
&amp;nbsp; &amp;nbsp;ENDSUB;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there nay way to resolve the above errors to make this program work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 15:09:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/I-want-to-calculate-Variable-label-only-when-Variable-is-not/m-p/572780#M75347</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-11T15:09:47Z</dc:date>
    </item>
    <item>
      <title>Re: I want to calculate Variable label only when Variable is not null.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/I-want-to-calculate-Variable-label-only-when-Variable-is-not/m-p/572828#M75352</link>
      <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the dataset I have five Flag Columns of numeric datatype. It contains data either 1 or no data(.)&lt;/P&gt;&lt;P&gt;Task is to check if the column is flaged then their labels should be concatenated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I use below statement, it will simply concatenate Labels for all the 5 variable irrespective of the data in it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA new;
SET old;
   new_col = catx(', ',VLABEL(var1), VLABEL(var2), VLABEL(var3), 
                       VLABEL(var4), VLABEL(var5));
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I though to write a Function as below so that I can pass each column to this function to get Label only when it contains data (doesn't matter what).&lt;/P&gt;&lt;P&gt;And I got the errors as mention in my original post.&lt;/P&gt;&lt;P&gt;(I forgot about function IFC to be honest &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; )&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;PROC&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;FCMP&lt;/SPAN&gt; OUTLIB &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; work&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;usrfunc&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;label&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
   FUNCTION &lt;CODE class=" language-sas"&gt;&lt;FONT color="#993366"&gt;varlbl&lt;/FONT&gt;&lt;/CODE&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;IF&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;NOT&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;MISSING&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;THEN&lt;/SPAN&gt; RETURN &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;VLABEL&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; ENDSUB&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;RUN&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;BR /&gt;&lt;CODE class=" language-sas"&gt;DATA new;
SET old;
   new_col = catx(', ',&lt;FONT color="#993366"&gt;&lt;CODE class="  language-sas"&gt;varlbl&lt;/CODE&gt;&lt;/FONT&gt;(var1), &lt;FONT color="#993366"&gt;&lt;CODE class="  language-sas"&gt;varlbl&lt;/CODE&gt;&lt;/FONT&gt;(var2), &lt;FONT color="#993366"&gt;&lt;CODE class="  language-sas"&gt;varlbl&lt;/CODE&gt;&lt;/FONT&gt;(var3), &lt;FONT color="#993366"&gt;&lt;CODE class="  language-sas"&gt;varlbl&lt;/CODE&gt;&lt;/FONT&gt;(var4), &lt;FONT color="#993366"&gt;&lt;CODE class="  language-sas"&gt;varlbl&lt;/CODE&gt;&lt;/FONT&gt;(var5)); RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have now used IFC function. It is working for me and I am able to achieve what I want.&lt;/P&gt;&lt;P&gt;But I still have this question, how we can use SAS function in&amp;nbsp; PROC FCMP.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 16:37:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/I-want-to-calculate-Variable-label-only-when-Variable-is-not/m-p/572828#M75352</guid>
      <dc:creator>sas_clin_usr</dc:creator>
      <dc:date>2019-07-11T16:37:19Z</dc:date>
    </item>
    <item>
      <title>Re: I want to calculate Variable label only when Variable is not null.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/I-want-to-calculate-Variable-label-only-when-Variable-is-not/m-p/572829#M75353</link>
      <description>&lt;P&gt;Thank you Tom!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried it and it is working form me &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 16:38:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/I-want-to-calculate-Variable-label-only-when-Variable-is-not/m-p/572829#M75353</guid>
      <dc:creator>sas_clin_usr</dc:creator>
      <dc:date>2019-07-11T16:38:36Z</dc:date>
    </item>
    <item>
      <title>Re: I want to calculate Variable label only when Variable is not null.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/I-want-to-calculate-Variable-label-only-when-Variable-is-not/m-p/572830#M75354</link>
      <description>&lt;P&gt;You can use many SAS functions in FCMP.&lt;/P&gt;
&lt;P&gt;You cannot use something like VLABEL that only makes sense in a data step.&amp;nbsp; That is also why you cannot use that function in %SYSFUNC() or PROC SQL.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 16:39:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/I-want-to-calculate-Variable-label-only-when-Variable-is-not/m-p/572830#M75354</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-11T16:39:09Z</dc:date>
    </item>
    <item>
      <title>Re: I want to calculate Variable label only when Variable is not null.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/I-want-to-calculate-Variable-label-only-when-Variable-is-not/m-p/572833#M75355</link>
      <description>Thank you tom for the feedback!</description>
      <pubDate>Thu, 11 Jul 2019 16:42:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/I-want-to-calculate-Variable-label-only-when-Variable-is-not/m-p/572833#M75355</guid>
      <dc:creator>sas_clin_usr</dc:creator>
      <dc:date>2019-07-11T16:42:28Z</dc:date>
    </item>
  </channel>
</rss>

