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
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?
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?
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.
Please supply example data (a dataset with vary as in your original dataset, in a data step with datalines).
not sure what I missed, but you are correct.
it is working now.
thanks a lot!!!
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.