DATA Step, Macro, Functions and more

Converting Character Data to Numeric Values

Reply
Occasional Contributor
Posts: 7

Converting Character Data to Numeric Values

I have a data set like:

 

F1   F2

0-4 110
5-9 105
10-14 96

 

I want to transfer F1, 0-4 to 1, 5-9 to 2, 10-14 to 3.

What is the best way?

 

 

Super User
Posts: 23,683

Re: Converting Character Data to Numeric Values

Posted in reply to walterwang

Multiple ways, probably just enumeration is best in this case. This may not scale depending on your exact logic, but given what you've shown, this works. 

 

data want;
set sashelp.class;
Order = _n_;
run;

@walterwang wrote:

I have a data set like:

 

F1   F2

0-4 110
5-9 105
10-14 96

 

I want to transfer F1, 0-4 to 1, 5-9 to 2, 10-14 to 3.

What is the best way?

 

 


 

Ask a Question
Discussion stats
  • 1 reply
  • 42 views
  • 0 likes
  • 2 in conversation