BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Calcite | Level 5

## Convert a variable length character to numeric while enforcing fix output length

hello guys,

I have a variable-length variable and need to convert it to numeric while enforcing a fix-length (12 digits) variable.

I haven't been able to accomplish it.

I am converting it to numeric.... but with leading spaces

how can I have leading zeroes instead of spaces before significant digits?

I have tried several including:

Format varx z12.;

varx = input(vary,12.);

or

varx = put(input(vary,12.),z12);

or at the end

varx = varx * 1;

still I am getting leading spaces.

How can I fix it to leading zeroes? Need it for another language.

Thank you so much

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: Convert a variable length character to numeric while enforcing fix output length

The first method should work:

``````Format varx z12.;
varx = input(vary,12.);``````

What does the log say? And which values do you have in vary?

5 REPLIES 5
Super User

## Re: Convert a variable length character to numeric while enforcing fix output length

The first method should work:

``````Format varx z12.;
varx = input(vary,12.);``````

What does the log say? And which values do you have in vary?

Calcite | Level 5

## Re: Convert a variable length character to numeric while enforcing fix output length

it does convert it to numeric.

but doesn't  hold the length as requested.

I am even have a put statement like this (to indicate where the variable ends)

put 'varx is ' varx ' end';

and it is written as

varx is 100 end

varx is 8 end

etc.

so. no sign of even the length of twelve being taken.

The output file looks fine, though. with the correct length ... but with leading blanks.

Thanks for following up, Kurt.

Super User

## Re: Convert a variable length character to numeric while enforcing fix output length

Please supply example data (a dataset with vary as in your original dataset, in a data step with datalines).

Calcite | Level 5

## Re: Convert a variable length character to numeric while enforcing fix output length

not sure what I missed, but you are correct.

it is working now.

thanks a lot!!!

Garnet | Level 18

## Re: Convert a variable length character to numeric while enforcing fix output length

You missed the dot in the format z12. :

varx = put(input(vary,12.),z12.);

In this case varx should be defined as char type: \$12

Discussion stats
• 5 replies
• 2269 views
• 0 likes
• 3 in conversation