- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.??
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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