sas >> How to convert character format to numeric format?

by Fei » Fri, 22 Sep 2006 15:19:43 GMT

Hi guys:

I imported date data from Excel to SAS. For some reasons, SAS
recognised this variable as character. I do not want to re-import it
again, but I need numeric format! Is there a code to convert this
variable to numeric?

Thanks


sas >> How to convert character format to numeric format?

by Eric Hoogenboom » Fri, 22 Sep 2006 15:30:14 GMT


Fei,

try the input function. Suppose your date string is in ddmmyy format,
see code below:

data char;
day1 = '22-09-2006';
date1 = input(day1, ddmmyy10.);
format date1 date9.;
put (_ALL_) (=);
run;

Hth,
Eric

sas >> How to convert character format to numeric format?

by aihuawang » Sat, 23 Sep 2006 21:04:48 GMT

Hi Fei:

Try this:

length v2 8.;
v2=put(v1, 8.);
drop v1;
rename v2=v1;

Note: v2 is a numerical variable, v1 is the character
variable.

Good luck,
Aihua


Hi guys:

I imported date data from Excel to SAS. For some
reasons, SAS
recognised this variable as character. I do not want
to re-import it
again, but I need numeric format! Is there a code to
convert this
variable to numeric?

Thanks



__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

sas >> How to convert character format to numeric format?

by jim2stat » Mon, 25 Sep 2006 19:10:41 GMT

Hi Joey,

%* Q&D macro aRecodeN "converts" character variables into numerical ones while;
%* preserving attributes. aRecodeN vs. 0.1.1a (C) Jim Groeneveld, Netherlands ;

See http://home.hccnet.nl/jim.groeneveld/software/SASmacro/aRecodeN.zip

Regards - Jim.

Similar Threads

1. convert a var from numeric to character without removing the label and format

2. Convert the month to a proper numeric format so that MDY

Your INPUT functions should be using numeric informats rather than character ones. I think that's the root of your problem.

Try this:

Num_date
=mdy(month(INPUT(month!!'01',monyy5.)),INPUT(date,2.),INPUT(year,4.));

HTH,
Tim

PS I saw Chang's solution before I sent this, and his is more elegant and I recommend it; but I'm sending this so you understand what the original problem was.


Tim Kynerd
Computer Programmer/Analyst
ECD/HOPE
4 Old River Place, Suite A
Jackson, MS 39202
P: (601) 944-9308
F: (601) 944-0808
 XXXX@XXXXX.COM 


-----Original Message-----
From: SAS(r) Discussion [mailto: XXXX@XXXXX.COM ] On Behalf Of SAS_learner
Sent: Thursday, June 05, 2008 3:44 PM
To:  XXXX@XXXXX.COM 
Subject: Convert the month to a proper numeric format so that MDY function works properly

hello guys I am using following technique but SAS Program is complaining in
the Log about the Character to Numeric conversion, Instead of this I can
write a bunch of if /then else statements which I do not want.Is there a
better way if doing it  without the Log Complaint

data aa;
  date = '01' ; month = 'JAN'; YEAR= '1998'; OUTPUT ;
  date = '02' ; month = 'FEB'; YEAR= '1998'; OUTPUT ;
  date = '03' ; month = 'MAR'; YEAR= '1998'; OUTPUT ;
  date = '04' ; month = 'APR'; YEAR= '1998'; OUTPUT ;
  Run;

 data aa;
    set aa;
Num_date
=mdy(month(INPUT(month!!'01',monyy5.)),INPUT(date,$3.),INPUT(year,$4.));
 Run;

NOTE: Character values have been converted to numeric
      values at the places given by: (Line):(Column).
      6842:49   6842:65
NOTE: There were 4 observations read from the data set WORK.AA.
NOTE: The data set WORK.AA has 4 observations and 4 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

This transmission is intended only for the use of the addressee and may contain information that is privileged, confidential, and exempt from disclosure under applicable law.  If you are not the intended recipient, or the employee or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution, or copying of this communication is strictly prohibited.  If you have received this communication in error, please notify us immediately via e-mail at  XXXX@XXXXX.COM .

3. Convert the month to a proper numeric format so that MDY function

4. Convert a numeric value to a sas date format

Hello
I have a column of values

LNKDT
19850330
19850331

etc.

and I can't use the year function on year(LNKDT) and because the LNKDT
column is not in the right format a sas date variable. Let me know how
to go about doing this.
I also there are cases in the LNKDT that are missing or have the
letter E meaning it doesn't exist so I want it not to return anything
in that case, but my main concern is converting this numeric value in
a format that I can use the year function on it.

-Barry

5. Convert to numeric where Date field Numeric and Character

6. Proc Format: Character to Numeric

Hello,

=20

I think it should be simple but having some issues.  Using proc format
to reformat a character to a numeric for ordering purposes.

=20

proc format;

=20

  invalue orderfmt

          'Lab ES'=3D1

          'Lab GP'=3D2

          'Lab RS'=3D3;

run;

=20

data fmt_lavs;

   set labs;

=20

 ord=3Dput(labc, orderfmt.);

=20

run;

=20

output data looks like:

=20

             obs       labc        ord

1                 Lab GP    La

2                 Lab RS    La

3                 Lab ES    La

=20

I would like to get:

=20

            obs       labc       ord

1                 Lab GP    2

2                 Lab RS    3

3                 Lab ES    1

=20

Any suggestions, thanks in advance

=20

Cheers,

Jessica

=20

=20

7. correct "read-in" and display format to handle mixed character and numeric values

8. Perserving character format on output output of a numeric value

I have read in an input file and one of the variables is ACCT_TXT which is
defined has :$48. (character).

And it hums along unitl it comes to some numbers in the field and it
sometimes outputs them in exponential notation(whenever number is greater
than 9 digits long) and I want it left in regular number format
(character)...

see below:
ACCT_CODE ACCT_TXT
METL7079    IMCS CICS APPL SECURITY
METL7088    MET REVIEW STATS
METL7105    UHC CUSTOMER RPTG
METL7108    MICR REPRINT
METL9340    UNITED FRONT END
METL9885    LASER NET
METP0001    2.00107E+11
METP0002    301230912

The 2.00107E+11 should read 200107201413...
I can I preserve the actual numeric number versus the exponential it
outputs???

Thanks, Jim