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.
What possible value would there be in such a function?
Just use normal SAS code
IFC(NOT MISSING (var),VLABEL(var),' ')
What possible value would there be in such a function?
Just use normal SAS code
IFC(NOT MISSING (var),VLABEL(var),' ')
Thank you Tom!
I tried it and it is working form me 🙂
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.
@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.
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.
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.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: