converting variable type fron character to numeric

Reply
Occasional Contributor
Posts: 10

converting variable type fron character to numeric

I need help in converting variable type from character to numeric.  I want to concatenate 3 datasets but I then discover that one variable defined as numeric in 2 of the datasets while it was character in the 3rd datasets.  How do i go about this?

Thanks.

fadtt

Frequent Contributor
Posts: 81

converting variable type fron character to numeric

You can use input function to convert Character values to Numeric values. You may change the informat based on your data.

For e.g. numvar = input(charvar,best.);

Occasional Contributor
Posts: 10

converting variable type fron character to numeric

Thanks, I already tried the input function but the type did not change thereby preventing me from concatenating the datasets.

Frequent Contributor
Posts: 81

converting variable type fron character to numeric

It would help if you can post your sample data and code.

Occasional Contributor
Posts: 10

converting variable type fron character to numeric

Thanks NickR,

I tried it again and it worked. I was amazed. I appreciate it.

fadtt

Trusted Advisor
Posts: 2,113

converting variable type fron character to numeric

Fadtt,

This post would be better in the SAS Macro, Data Step... Community.  This community is for getting started with using Communities, not for getting started with using SAS.

You got your answer, and that's good, but more people would have seen it in the other forum.

Doc Muhlbaier

Duke

Occasional Contributor
Posts: 10

converting variable type fron character to numeric

Did I offend you by posting my question because I don't understand your comment.

Trusted Advisor
Posts: 2,113

converting variable type fron character to numeric

No offense at all.  I saw you hadn't posted before and was offering a suggestion for more effective posting. 

There are lots of Forums for posting questions at http://communities.sas.com/index.jspa .  The one that is most pertinent to your question is "SAS Macro Facility, Data Step, and SAS Language Elements". 

This Forum ("Getting Started: Community Instructions, Usage Tips, and Feedback") is designed for comments and questions about how to use the SAS Communities system itself.  Right now, because SAS just moed to this platform, there are a lot of people watching this forum.  As people get more comfortable with the process, there are likely to be fewer and fewer people looking at it to be available to answer SAS usage questions.

Doc Muhlbaier

Duke

Occasional Contributor
Posts: 10

converting variable type fron character to numeric

I appreciate your advise. I am a bit new to discussion forum but I needed help at the time I just decided to make use of what I have on hand.

Contributor QLi
Contributor
Posts: 57

converting variable type fron character to numeric

another way to change Character variable to numeric variable,

    Char_Var *1;

or  Char_Var+0;

Ask a Question
Discussion stats
  • 9 replies
  • 456 views
  • 0 likes
  • 4 in conversation