Hello valued SAS experts,
I am facing the challenge described below and would appreciate an approach/idea on how to solve the problem. My dataset have looks like this:
data have;
input
ID $
;
datalines;
VW
1
2
3
4
5
BMW
6
7
8
9
10
;
run;
In the target dataset want there should be a new variable CAR_BRAND which should be created based on the ID according to the following rule:
Always fill the variable CAR_BRAND with the last non-digit string from the variable ID. Accordingly, the dataset want should look like this at the end:
data want;
input
ID $
CAR_BRAND $
;
datalines;
VW VW
1 VW
2 VW
3 VW
4 VW
5 VW
BMW BMW
6 BMW
7 BMW
8 BMW
9 BMW
10 BMW
;
run;
Thanks in advance for the help/ideas!
Hi @owndan, welcome to the SAS Communities forum and thanks for supplying the data in the form of a data step.
Does the following help?
data want;
set have;
length car_brand $ 10;
retain car_brand;
if notdigit(strip(id)) then
car_brand = id;
run;
Thanks & kind regards,
Amir.
Hi @owndan, welcome to the SAS Communities forum and thanks for supplying the data in the form of a data step.
Does the following help?
data want;
set have;
length car_brand $ 10;
retain car_brand;
if notdigit(strip(id)) then
car_brand = id;
run;
Thanks & kind regards,
Amir.
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 25. 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.