Hey guys,
I hope this is a simple one, but I wasnt able to find anything on it when I googled. I have a dataset called values that holds 5 values and I want to do a check if my variable x is in that dataset so I can do if then logic.
values = value1, value2, value3, value4, value5
x = value2
if x in values then...
It is not at all clear what you are asking. Please provide a simple example of input data and output data and explain the logic.
What do you mean by "variable in data set"? Just the existence of the variable? Or is there some property of the variable's value that you want to test?
In general if you reference a variable in your code that doesn't exist in the input data then SAS will just create it and leave the values as missing until you assign some value in the code. Is that what you want to happen?
Get the names of variables in a dataset from dictionary.columns or sashelp.vcolumn:
%let present=0;
data _null_;
set sashelp.vcolumn (where=(libname = 'XX' and memname = 'VALUES' and upcase(name) = 'VALUE2'));
call symputx('present',1);
run;
Then you can run code later on the condition &present.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.