It would be helpful if you post some data -- even if it's just mocked up data.
One question I have is: Can "Toyota" or "Honda" appear within other text or is the brand name of the car in a column by itself?
For example, would your data look more like the "Brand" column below or would it look more like the "Car_Info" column below?
Brand | Car_Info |
Toyota | 2014 Toyota Camry |
If "Toyota" can appear anywhere in the column, then we need to take a different approach.
Jim
Dear Jim
Thanks for the input.
I realize that I should have specified this detail. The data is as Brand, but at some point I will need to find similar solutions for variables which are organised as 'Car_Info'. I believe another person posted code which would work in such a scenario (with 'Car_info').
Hi @mgrasmussen
Here is a slightly modified version of @tarheel13 's code. It uses an automatic array _characters_ containing all defined character variables (a smart SAS feature). The index function + lowcase identifies all occurences of Toyota or Honda in all character strings regardless of case or other content in the text.
data mydata;
set sashelp.cars;
array cars $ _character_;
flag='N';
do i=1 to dim(cars);
if index(lowcase(cars[i]),'toyota') or index(lowcase(cars[i]),'honda') then flag='Y';
end;
if flag='Y' then delete;
run;
Dear Erik
Thanks. These are great features and would work in my case.
What is the purpose of the lowcase function? I believe I understand what it does, but why is it necessary here? I would suspect that this specification is related to the fact that you write 'toyota' and 'honda' within the code in brackets.
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.