DATA Step, Macro, Functions and more

changing numeric to character

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

changing numeric to character

I have a code with a data set with a variable titled average with the average housing prices by month since 1975. These observations are in char format and need to be converted to numerics. The code is below:

 

data mortdata.housingproces; set mortdata.house_price;

AVG = input(average, Best5.);

run;

 

This isn't working, and I'd like to know why. The output that I keep getting is just "." for all the rows.

 

Thank you for your help in advance!  

 

 


Accepted Solutions
Solution
‎09-11-2017 06:16 PM
Super User
Posts: 11,343

Re: changing numeric to character

Posted in reply to uttara_96

Does you text value have commas? Show some example values, what you are currently getting for results and what you expect.

 

View solution in original post


All Replies
Super User
Posts: 19,855

Re: changing numeric to character

Posted in reply to uttara_96

BEST5 seems low for house prices, have you tried BEST12?

 

Post your log as well please.

New Contributor
Posts: 4

Re: changing numeric to character

I tried BEST12, but the output was the same.
Super User
Posts: 19,855

Re: changing numeric to character

Posted in reply to uttara_96

Post your code and log.

Solution
‎09-11-2017 06:16 PM
Super User
Posts: 11,343

Re: changing numeric to character

Posted in reply to uttara_96

Does you text value have commas? Show some example values, what you are currently getting for results and what you expect.

 

New Contributor
Posts: 4

Re: changing numeric to character

[ Edited ]

My text values had commas in them, and I removed them right now. The results are now populating. Thank you so much for y'all's help!

Super User
Posts: 19,855

Re: changing numeric to character

Posted in reply to uttara_96

The informat represents the format your data was in.

 

So it should have been something like:

 

input(average, comma12.);

 

Frequent Contributor
Posts: 100

Re: changing numeric to character

Posted in reply to uttara_96

 

 

data mortdata.housingproces; set mortdata.house_price;

AVG = average+0;

run;

Super User
Posts: 19,855

Re: changing numeric to character

Posted in reply to ShiroAmada

ShiroAmada wrote:

 

 

data mortdata.housingproces; set mortdata.house_price;

AVG = average+0;

run;


Implicit conversion isn't a great idea in the long run. It will leave notes in the log and make it hard to distinguish actual errors, if they crop up later on. 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 100 views
  • 4 likes
  • 4 in conversation