## How can I convert a character value with leading zeros to numeric and maintain the leading zeros?

Solved
Frequent Contributor
Posts: 82

# How can I convert a character value with leading zeros to numeric and maintain the leading zeros?

I have a data item (is SSN) that is defined with character format. The ssn does NOT have any dashes, just numbers.   I need to convert this to numeric without losing the leading zeros.  I do not see any functions that would do this.  Any suggestions on how I can accomplish this?

Thanks!

Accepted Solutions
Solution
‎03-02-2012 01:34 PM
New Contributor
Posts: 3

## How can I convert a character value with leading zeros to numeric and maintain the leading zeros?

Hi, you can convert the ssn into numeric but define the format as Zw.d. eg:

data test;

x='0001451';

run;

data t1;

set test;

format y z7.;

y=x*1;

run;

All Replies
Super User
Posts: 8,216

## Re: How can I convert a character value with leading zeros to numeric and maintain the leading zeros?

Slightly more involved than I originally posted.  You have to use a mixture of put and input functions:

data have;

input x \$;

z=put(input(x,9.),z9.);

cards;

1

11

111

;

Contributor
Posts: 40

## How can I convert a character value with leading zeros to numeric and maintain the leading zeros?

Solution
‎03-02-2012 01:34 PM
New Contributor
Posts: 3

## How can I convert a character value with leading zeros to numeric and maintain the leading zeros?

Hi, you can convert the ssn into numeric but define the format as Zw.d. eg:

data test;

x='0001451';

run;

data t1;

set test;

format y z7.;

y=x*1;

run;

🔒 This topic is solved and locked.