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

I have a column for AIS (abbreviation injury score) per patient line of data. Each patient has multiple AISs and the last two digits have spaces between them. I'd like to pull the last two decimals into their own variable columns:

 

data have: 

studyid            AIS

1                541626 4 4

1                544224 3 4            

2                544222 2 4

2                450203 3 3

 

data want:

study id         Injury severity    Injury region

1                         4                          4

1                         3                          4

2                         2                          4

2                         3                          3

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

This perhaps?

data want;
   set have;
   
   severity= scan(AIS,2);
   region= scan(AIS,3);
   /* and maybe to have the other value
   stripped of the last two*/
   ais = scan(ais,1);
run;

You have a character value, other wise there could not be spaces embedded. So SCAN will pull pieces separated by spaces (and other delimiting characters as needed).

View solution in original post

2 REPLIES 2
ballardw
Super User

This perhaps?

data want;
   set have;
   
   severity= scan(AIS,2);
   region= scan(AIS,3);
   /* and maybe to have the other value
   stripped of the last two*/
   ais = scan(ais,1);
run;

You have a character value, other wise there could not be spaces embedded. So SCAN will pull pieces separated by spaces (and other delimiting characters as needed).

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 2 replies
  • 670 views
  • 3 likes
  • 3 in conversation