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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.