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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Amir
PROC Star

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.

View solution in original post

1 REPLY 1
Amir
PROC Star

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.

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
  • 1 reply
  • 563 views
  • 1 like
  • 2 in conversation