BookmarkSubscribeRSS Feed
abrice520
Obsidian | Level 7

I'm trying to take maternal height in feet and inches and convert it to just inches. However, I've noticed that some of the data is entered in this format: 05:03 (for 5ft 3 inches) while other entries exclude the colon, so 0503. I'm looking for a way to either add the colon into those that have it missing or remove the colon, so that the data looks the same. Here is the code I was using before I realized this issue:

 

MHInch= scan(MotherHeight,1,":")*12 + scan(MotherHeight,2,":")*1;

Thanks!

1 REPLY 1
Patrick
Opal | Level 21

As long as you can rely that your source string is always 4 characters after removal of the column below should work.

If you can't be sure then please provide representative "have" sample data with all the potential patterns the code needs to work for.

data have;
  input MotherHeight $;
  MHInch=sum( 
              input(substr(MotherHeight,1,2),best32.)*12 
              ,input(substr(compress(MotherHeight,':'),3,2),best32.)
            );
datalines;
05:03
0503
;

Code like below could help you figure out what patterns you're dealing with.

proc sql;
  select distinct 
    prxchange('s/\d/9/',-1,strip(MotherHeight)) as pattern
  from have
  ;
quit;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 372 views
  • 0 likes
  • 2 in conversation