BookmarkSubscribeRSS Feed
fadtt
Calcite | Level 5

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

9 REPLIES 9
NickR
Quartz | Level 8

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.);

fadtt
Calcite | Level 5

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

NickR
Quartz | Level 8

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

fadtt
Calcite | Level 5

Thanks NickR,

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

fadtt

Doc_Duke
Rhodochrosite | Level 12

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

fadtt
Calcite | Level 5

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

Doc_Duke
Rhodochrosite | Level 12

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

fadtt
Calcite | Level 5

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.

QLi
Fluorite | Level 6 QLi
Fluorite | Level 6

another way to change Character variable to numeric variable,

    Char_Var *1;

or  Char_Var+0;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 903 views
  • 0 likes
  • 4 in conversation