LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (October 2000, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 20 Oct 2000 19:10:53 GMT
Reply-To:     Paul Dorfman <paul_dorfman@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Paul Dorfman <paul_dorfman@HOTMAIL.COM>
Subject:      Re: Suggestions Needed
Comments: To: susemichel_paul@LILLY.COM
Content-Type: text/plain; format=flowed

Paul,

First, it is hardly a very good idea to make SAS perform an unnecessary computation and let it convert implicitly - unless you crave for a SAS log full of conversion notes. Instead, use the INPUT() function designed for this purpose:

Num_Var = input (Char_Var, best<length>.);

Instead of <length>, supply the maximum length Char_Var may have. Secondly, do not confuse a group of identically prefixed variables or variables having a similar name pattern with arrays. An array can embrace any variables regardless of their names and/or length, the only rule being that they should have the same type. Thus, for example, if you have variables A B C with length 1, 2, 3 respectively, you can still use array processing:

data a; retain a '1' b '12' c '1.2'; run;

data b; set a; array arc a b c ; array arn an bn cn; do over arc; arn = input (arc, best3.); end; run;

If you need to convert *all* character variables to numbers, it may be more convenient to use the _character_ specification in the array ARC declaration and sequentially suffixed variable names on the receiving numeric side:

array arc _character_; array afn n1-n3;

Kind regards, ======================= Paul M. Dorfman Jacksonville, Fl =======================

>From: Paul Susemichel <susemichel_paul@LILLY.COM> >Reply-To: Paul Susemichel <susemichel_paul@LILLY.COM> >To: SAS-L@LISTSERV.UGA.EDU >Subject: Suggestions Needed >Date: Fri, 20 Oct 2000 18:24:17 GMT > >Not being a proficient SAS programmer, I was hoping for suggestions on the >best way to code the following problem: > >The basic concept of what I need to do is to convert the value of a >character variable to numeric and assign that value a new variable name. I >figured the basic logic would be something like: > > if Char_Var ne . then > Num_Var = Char_Var + 0; > else > Num_Var = .; > >Unfortunately, I need to do this for 161 seperate variables -- no arrays or >patterns -- which makes for a lot of code to do the same thing. I've tried >to think of ways that would allow me to do this much more efficiently, but >have been unsuccessful. > >Thanks in advance for any help. > > >Paul

_________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Share information about yourself, create your own public profile at http://profiles.msn.com.


Back to: Top of message | Previous page | Main SAS-L page