I have data imputs in my data that I need to change.
The first one is CarMax # 10000 and the other is DriveTime 10000
I want all instances of CarMax # 100000 to be "CarMax" and DriveTime 10000 to be "DriveTime".
They both have different locations so it could be 100001, 100002 and so on same for DriveTime.
CASE WHEN Sales.Dlr_Name LIKE 'CarMax%'
THEN "CarMax"
WHEN LEFT (Sales.Dlr_Name,9)
THEN "Drivetime"
ELSE Sales.Dlr_Name
END AS Dlr_Name,
When I use this it only returns CarMax in the results
Help, please
If you are using explicit pass-through method to access T-SQL from SAS, I have no idea what happened. You seem to have coded just right. If you are not using pass-through, then you will need change your code to the SAS SQL style. for example:
case when upcase(left(Sales.Dlr_Name)) eqt 'CARMAX' THEN 'CARMAX'
WHEN upcase(left(Sales.Dlr_Name)) eqt 'DRIVETIME' then 'DRIVETIME'
ELSE Sales.Dlr_Name
END AS Dlr_Name
or using substr, like, contain, find or index functions.
I mixed up the codes from when I pasted it, was trying either the LIKE or the LEFT
LIKE only brought back Carmax, LEFT did the same thing.....
Your syntax is a little off, you will need two 'CASE WHEN .... END' for two variables.
Give a few examples of your incoming data and your expected outcomes, if you could.
So this is from one variable called " Dlr_Name "?
If you are using explicit pass-through method to access T-SQL from SAS, I have no idea what happened. You seem to have coded just right. If you are not using pass-through, then you will need change your code to the SAS SQL style. for example:
case when upcase(left(Sales.Dlr_Name)) eqt 'CARMAX' THEN 'CARMAX'
WHEN upcase(left(Sales.Dlr_Name)) eqt 'DRIVETIME' then 'DRIVETIME'
ELSE Sales.Dlr_Name
END AS Dlr_Name
or using substr, like, contain, find or index functions.
Thank you! I added the UPCASE and the () around LEFT() and used EQT instead of = and bingo in business.
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 16. 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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: