BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sas_clin_usr
Fluorite | Level 6

Hi All,

 

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:  ERROR: The VLABEL function is only valid in the DATA step. User defined libraries will be searched for a definition of this
function.

PROC FCMP OUTLIB = work.usrfunc.label;
   FUNCTION varlbl(var);
      IF NOT MISSING (var) THEN RETURN (VLABEL(var));
   ENDSUB;
RUN;

 

I tried using %SYSFUNC as below but I got another error: ERROR: The function VLABEL referenced by %SYSFUNC, %QSYSFUNC, or %SYSCALL cannot be used within the MACRO function/call-routine interfaces.

PROC FCMP OUTLIB = work.usrfunc.label;
   FUNCTION varlbl(var);
      IF NOT MISSING (var) THEN RETURN (%SYSFUNC(VLABEL(var)));
   ENDSUB;
RUN;

Is there nay way to resolve the above errors to make this program work.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

What possible value would there be in such a function?

Just use normal SAS code

IFC(NOT MISSING (var),VLABEL(var),' ')

View solution in original post

6 REPLIES 6
Tom
Super User Tom
Super User

What possible value would there be in such a function?

Just use normal SAS code

IFC(NOT MISSING (var),VLABEL(var),' ')
sas_clin_usr
Fluorite | Level 6

Thank you Tom!

 

I tried it and it is working form me 🙂

Reeza
Super User

What do you mean when a variable is null? Is that when all values in that variable are missing?

Or if a single value is missing?

 

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.

http://xyproblem.info/


@sas_clin_usr wrote:

Hi All,

 

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:  ERROR: The VLABEL function is only valid in the DATA step. User defined libraries will be searched for a definition of this
function.

PROC FCMP OUTLIB = work.usrfunc.label;
   FUNCTION varlbl(var);
      IF NOT MISSING (var) THEN RETURN (VLABEL(var));
   ENDSUB;
RUN;

 

I tried using %SYSFUNC as below but I got another error: ERROR: The function VLABEL referenced by %SYSFUNC, %QSYSFUNC, or %SYSCALL cannot be used within the MACRO function/call-routine interfaces.

PROC FCMP OUTLIB = work.usrfunc.label;
   FUNCTION varlbl(var);
      IF NOT MISSING (var) THEN RETURN (%SYSFUNC(VLABEL(var)));
   ENDSUB;
RUN;

Is there nay way to resolve the above errors to make this program work.

 


 

sas_clin_usr
Fluorite | Level 6

Hi Reeza,

 

In the dataset I have five Flag Columns of numeric datatype. It contains data either 1 or no data(.)

Task is to check if the column is flaged then their labels should be concatenated.

 

If I use below statement, it will simply concatenate Labels for all the 5 variable irrespective of the data in it.

 

 

DATA new;
SET old;
   new_col = catx(', ',VLABEL(var1), VLABEL(var2), VLABEL(var3), 
                       VLABEL(var4), VLABEL(var5));
RUN;

 

 

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).

And I got the errors as mention in my original post.

(I forgot about function IFC to be honest 😞

 

 

PROC FCMP OUTLIB = work.usrfunc.label;
   FUNCTION varlbl(var); IF NOT MISSING (var) THEN RETURN (VLABEL(var)); ENDSUB; RUN;

DATA new; SET old; new_col = catx(', ',varlbl(var1), varlbl(var2), varlbl(var3), varlbl(var4), varlbl(var5)); RUN;

 

 

 

I have now used IFC function. It is working for me and I am able to achieve what I want.

But I still have this question, how we can use SAS function in  PROC FCMP.

Tom
Super User Tom
Super User

You can use many SAS functions in FCMP.

You cannot use something like VLABEL that only makes sense in a data step.  That is also why you cannot use that function in %SYSFUNC() or PROC SQL.

sas_clin_usr
Fluorite | Level 6
Thank you tom for the feedback!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1171 views
  • 2 likes
  • 3 in conversation