- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
*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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;