BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TMiller16
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

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.

 

View solution in original post

9 REPLIES 9
TMiller16
Fluorite | Level 6

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.....

Haikuo
Onyx | Level 15

Your syntax is a little off, you will need two 'CASE WHEN .... END' for two variables.

 

 

 

TMiller16
Fluorite | Level 6
Right, like I said, I copied the "in progress" one. Here it is:

CASE WHEN Sales.Dlr_Name LIKE 'CarMax%'
THEN "CarMax"
CASE WHEN Sales.Dlr_Name LIKE 'Drivetime%'
THEN "Drivetime"
ELSE Sales.Dlr_Name
END AS Dlr_Name,
Haikuo
Onyx | Level 15

Give a few examples of your incoming data and your expected outcomes, if you could.

TMiller16
Fluorite | Level 6
CARMAX #7157
CARMAX #7521
CARMAX AUTO SUPERSTORES INC

These need to change to CarMax

DRIVETIME CAR SALES (PHOENIX< AZ)
DRIVETIME-BUYING ACCT

Should be DRIVETIME



Haikuo
Onyx | Level 15

So this is from one variable called " Dlr_Name "?

TMiller16
Fluorite | Level 6
Yes it is, this is what I have tried so far:

CASE WHEN LEFT (Sales.Dlr_Name,6) = "CARMAX"
THEN "CARMAX"
WHEN LEFT (Sales.Dlr_Name,9) = "DRIVETIME"
THEN "DRIVETIME"
ELSE Sales.Dlr_Name
END AS Dlr_Name,
Haikuo
Onyx | Level 15

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.

 

TMiller16
Fluorite | Level 6

Thank you!  I added the UPCASE and the () around LEFT() and used EQT instead of = and bingo in business.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 2554 views
  • 0 likes
  • 2 in conversation