Dick Duck's SAS tips

This is the nest where I keep my SAS eggs. It's all here... Arrays, control loops, links to online SAS resources, you name it.

Wednesday, February 15, 2006

Convert variable from character to numeric

Thanks to Paul Duckman for this. Suppose you have a datafile with a character variable (var) that you want to convert to a numeric variable. While this is not possible, the following code replaces the character variable with a numeric variable of the same name.

1. data datfile (drop = tmp);
2. set datfile (rename = (var = tmp));
3. var = input (tmp, best4.);
4. run;
On line 2, the character variable is renamed. One line 3, a new numeric variable is created, with the same name as the original character variable, and its value is set. On line 1, the temporary variable is deleted.

7 Comments:

Blogger Unknown said...

Thank you for this neat code! It is very helpful!

4:19 pm  
Anonymous Anonymous said...

Hello,

When ever I surf on web I come to this website[url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips].[/url]dickduckssastips.blogspot.com is filled with quality info. Do you pay attention towards your health?. Are you really serious about your weight?. Recent Research points that almost 60% of all USA grownups are either chubby or overweight[url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips].[/url] Therefore if you're one of these citizens, you're not alone. In fact, most of us need to lose a few pounds once in a while to get sexy and perfect six pack abs. Now the question is how you are planning to have quick weight loss? You can easily lose with with little effort. You need to improve some of you daily habbits to achive weight loss in short span of time.

About me: I am blogger of [url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips]Quick weight loss tips[/url]. I am also health expert who can help you lose weight quickly. If you do not want to go under painful training program than you may also try [url=http://www.weightrapidloss.com/acai-berry-for-quick-weight-loss]Acai Berry[/url] or [url=http://www.weightrapidloss.com/colon-cleanse-for-weight-loss]Colon Cleansing[/url] for quick weight loss.

12:02 am  
Anonymous Anonymous said...

Thanks for sharing this. Very helpful indeed.

6:21 pm  
Anonymous xxx beastiality stories said...

John put Alicesback to the wall to offer a profile shot as he rucked up her skirt andworked her panties down. Just because Ineed you now doesnt mean I wont kill you later, she spat.
free femdom stories
free male masturbation stories
free pony zoo porn stories
gay old men stories
erotic sex stories with pictures
John put Alicesback to the wall to offer a profile shot as he rucked up her skirt andworked her panties down. Just because Ineed you now doesnt mean I wont kill you later, she spat.

1:50 pm  
Anonymous Gaby said...

Unrelated, but yet somehow related to the problem posted.

I have a series of N data files that I am looping through and for N-2 data files variable x is numeric and for the last 2 is character. I need to append all these data and so I attempted to simply convert all x variables in all data files into numeric using the input function. However, for the first N-2 files, x becomes a character variable and for the 2 files it does become numeric! I am going crazy right now.
Even if I set new_x = x; where x is numeric, new_x appears as character. Any help is much appreciated!
Thanks!

11:31 am  
Anonymous Anonymous said...

What's up, after reading this awesome post i am too cheerful to share my experience here with mates.

My blog post; 38000ft.com

6:25 pm  
Anonymous Anonymous said...

I like the valuable info you provide in your articles.

I'll bookmark your weblog and check again here regularly. I am quite sure I'll learn many new stuff right
here! Best of luck for the next!

Feel free to visit my homepage; book of ra online spielen um echtes geld

3:39 pm  

Post a Comment

<< Home