DATA Step, Macro, Functions and more

How to create a numeric variable by taking numeric portion of a character variable

Reply
Super Contributor
Posts: 272

How to create a numeric variable by taking numeric portion of a character variable

Dear,

 

I have a variable 'TPT' containing numbers and text. I need to create a numeric variable (TPTNUM) from numeric portion of TPT. Please help

 

TPT

0.5 hours

1 hour

1.5 hours

2 hours

2.5 hours

 

output needed;

0.5

1

1.5

2

2.5

Thank you

Respected Advisor
Posts: 4,649

Re: How to create a numeric variable by taking numeric portion of a character variable

If the number is the first part of the field:

 

TPTNUM = input(scan(TPT, 1, " "), best.);

PG
Ask a Question
Discussion stats
  • 1 reply
  • 182 views
  • 1 like
  • 2 in conversation