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

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

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.);

View solution in original post

3 REPLIES 3
SASKiwi
PROC Star

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.

ballardw
Super User

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.);

pallis
Fluorite | Level 6

Thank you Smiley Happy

suga badge.PNGThe SAS Users Group for Administrators (SUGA) is open to all SAS administrators and architects who install, update, manage or maintain a SAS deployment. 

Join SUGA 

CLI in SAS Viya

Learn how to install the SAS Viya CLI and a few commands you may find useful in this video by SAS’ Darrell Barton.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1542 views
  • 3 likes
  • 3 in conversation