DATA Step, Macro, Functions and more

convert charac variable with alphabets and number combination into numeric.

Reply
Frequent Learner
Posts: 1

convert charac variable with alphabets and number combination into numeric.

Hi all,

 

I am running into problem. I have a ID fields  eg: 0803M0000274  and 0526842935 in charc format and want to both convert it into numeric. 

im using

INPUT(ID,BEST32.) as ID1 and this returns a blank for only alphanumeric field. How do i fix this. I m using Base SAS.

 

Help is appreciated. 

 

Regular Contributor
Posts: 161

Re: convert charac variable with alphabets and number combination into numeric.

are you sure you need a numeric subject id? i can't imagine why you would. but if you do: just create another numeric variable counting from 1 to n.  i wouldn't tamper with the original id variable, eg you may later obtain new data (with the old id) and your only link will be the subject id, and many other unanticipated issues could arise eg if you converse with others who also access the data but have not recreated id in the same way .... etc

--------------
blog: papersandprograms.com
Respected Advisor
Posts: 3,019

Re: convert charac variable with alphabets and number combination into numeric.

0803M0000274 can't be converted to numeric

 

Perhaps you could explain further what you would like when converting this to numeric.

--
Paige Miller
Super User
Posts: 13,542

Re: convert charac variable with alphabets and number combination into numeric.

In addition to the other comments suppose you actually have Ids of 0526842935 and 526842935. Converting these to numeric could very well lead to problems as the leading 0 in the first one is likely there for a reason.

Super User
Posts: 10,255

Re: convert charac variable with alphabets and number combination into numeric.

[ Edited ]

DON'T DO THAT.

 

Imagine you also have an ID 0803N0000274.

ID's are character strings, you don't need them for calculating, so keep them as strings.


@viz2022 wrote:

Hi all,

 

I am running into problem. I have a ID fields  eg: 0803M0000274  and 0526842935 in charc format and want to both convert it into numeric. 

im using

INPUT(ID,BEST32.) as ID1 and this returns a blank for only alphanumeric field. How do i fix this. I m using Base SAS.

 

Help is appreciated. 

 


 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Respected Advisor
Posts: 4,736

Re: convert charac variable with alphabets and number combination into numeric.

@viz2022

I'm very much with @KurtBremser. Why do you want to do this? Are you having a problem with leading zero's and ID's for the same person sometimes with and sometimes without leading zeros?

Ask a Question
Discussion stats
  • 5 replies
  • 84 views
  • 0 likes
  • 6 in conversation