sas

How to convert a character variable with numbers with a comma into numeric


I have a set of variables in SAS that should be numeric but are characters. Numbers are comma separated and I need a point. For example, I need 19,000417537 to be 19.000417537. I tried translate without success; the comma is still there and I'm not able to convert the variable to numeric using input(). What can I try next?


Solution

  • Use INPUT() with the COMMAX informat.

    data have;
    length have $20.;
    have = "19,000417537";
    want = input(have, commax32.);
    format want 32.8;
    run;
    
    proc print data=have;
    run;
    
    Obs have    want
    1   19,000417537    19.00041754