*I used %nrstr to simplify the following check and it worked. I checked here if the tree_types falls under any of the following:
'999', '888', '777', '444', '555', '666', '124', '543', '567', '987', '342', '123', '678', '876', '123', '432',
'657', '453', '125', '665', '776', '887', '567'. If it falls under any of these types then it is flagged as '1'.;
%let tree = %nrstr ('999', '888', '777', '444', '555', '666', '124', '543', '567', '987', '342', '123', '678', '876', '123',
'432', '657', '453', '125', '665', '776', '887', '567');
data want;
set have;
if tree_type in (&tree) then tree_type=1;
run;
proc print data=want;
where tree_type in (1);
var id;
run;
*Now I am thinking what is the alternative if I want to check many strings in one check like this. Such as in place of
('999', '888', '777', '444', '555', '666', '124', '543', '567', '987', '342', '123', '678', '876', '123', '432',
'657', '453', '125', '665', '776', '887', '567') there will be strings such as ('sbc', 'THe end', 'dfi', 'gas', 'Grt'...etc.)
some strings are upper case, some are lower case, some are both upper and lower case, some has more than one word. Any suggestion
would be appreciated. Thank you.
Please describe exactly what you are attempting to do. This may include an example of what the source data looks like and what the desired output should look like, best as data steps to create data sets so there are no questions about the data.
Why do you think you need any macro variables for this project?
1) All given tree codes seem to be numeric. I assume this is the real situation.
in case some tree codes may be alphanumeric just change the type.
2) The alternative logic is to have the tree codes as a dataset and merge it with your HAVE dataset:
data tree_codes;
infile cards;
input tree_type; /* add $ for char type */
cards;
999
888
777
444
.....
; run;
proc sort data=tree_codes; by tree_type; run;
proc sort data=have; by tree_type; run;
data want;
merge have (in=in1)
tree_codes(in=in2);
by tree_type;
if in1 and in2 then tree_type=1;
run;
proc print data=want(where=(tree_type=1));
var id;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.