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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 265 views
  • 1 like
  • 2 in conversation