Solved
Contributor
Posts: 71

# Loop Help

data a6;

a=12345;

b=0;

/*do while (A >0);*/

do i=1 to length(a);

b=(b*10)+mod(a,10);

a=int(a/10);

put _all_;

end;

run;

When I run this code instead of 4 My loop is runs for 12 times Can any one explain me .

Regards,

venkay

Accepted Solutions
Solution
‎08-05-2014 11:04 AM
Super User
Posts: 13,358

## Re: Loop Help

And if you are trying to reverse the number

b = input(reverse(put(a,f5.)),f5.);

or if looking for the last 4 digits

b = input(substr(reverse(put(a,f5.)),1,4),f5.);

All Replies
Super User
Posts: 3,866

## Re: Loop Help

The reason is you are applying a character function - LENGTH - to a number - 12345. So SAS is automatically converting the number into a character variable using the BEST12. SAS format.

Inside SAS your number now looks like this (ignore the surrounding quotes) - '       12345' - in other words it has 7 blank spaces in front of the number.

So that is why your look runs 12 times. If you changed a=12345 to a='12345' it would loop 5 times.

Solution
‎08-05-2014 11:04 AM
Super User
Posts: 13,358

## Re: Loop Help

And if you are trying to reverse the number

b = input(reverse(put(a,f5.)),f5.);

or if looking for the last 4 digits

b = input(substr(reverse(put(a,f5.)),1,4),f5.);

Contributor
Posts: 71

## Re: Loop Help

Thank you

🔒 This topic is solved and locked.