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

suppose i have a column named number and it has a value like 6458903 and i want this value in target table as 6500000

and its length is not fixed how we can do this.??

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You would use the round function.  However you would first take the lengthn(put(number,best.)), then remove 2 from that and then use that to create your rounding amount.  Something like:

data want;
  orig=6458903;
  num=lengthn(strip(put(orig,best.)))-2;
  roundto=cats("1",repeat("0",num-1));
  new=round(orig,roundto);
run;

Note I have specifically left all the working out and made it verbose to show the process, you can shrink it down.

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You would use the round function.  However you would first take the lengthn(put(number,best.)), then remove 2 from that and then use that to create your rounding amount.  Something like:

data want;
  orig=6458903;
  num=lengthn(strip(put(orig,best.)))-2;
  roundto=cats("1",repeat("0",num-1));
  new=round(orig,roundto);
run;

Note I have specifically left all the working out and made it verbose to show the process, you can shrink it down.

Son_Of_Krypton
Fluorite | Level 6
Thanks for the solution '_'
data_null__
Jade | Level 19
146  data _null_;
147     do orig=6458903,670,456123,32,645890,64589,6458,645,64,6;
148        l = ceil(log10(orig));
149        u = 10**(l-2);
150        round = round(orig,U);
151        put (_all_)(=);
152        end;
153     run;

orig=6458903 l=7 u=100000 round=6500000
orig=670 l=3 u=10 round=670
orig=456123 l=6 u=10000 round=460000
orig=32 l=2 u=1 round=32
orig=645890 l=6 u=10000 round=650000
orig=64589 l=5 u=1000 round=65000
orig=6458 l=4 u=100 round=6500
orig=645 l=3 u=10 round=650
orig=64 l=2 u=1 round=64
orig=6 l=1 u=0.1 round=6

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 1474 views
  • 0 likes
  • 3 in conversation