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

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
5 REPLIES 5
shikoulitz
Calcite | Level 5

 

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.

shikoulitz
Calcite | Level 5

not sure what I missed, but you are correct.

it is working now.

thanks a lot!!!

Shmuel
Garnet | Level 18

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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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