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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.