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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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