I have the different numeric variable with different number of digits after the decimal. Is it possible to convert them to same number of digits after decimal in one attempt by ROUNDING the digits, instead of applying the format each variable separately. Thank you
data orci;
input effect$ a b c d e f;
cards;
points 1.05 1.055 1.0554 1.05545 1.055454 1.055455
;
run;
@SASuserlot wrote:
Is it possible to convert them to same number of digits after decimal in one attempt by ROUNDING the digits, instead of applying the format each variable separately.
You could round the values one variable at a time, I don't see how that's any better than formatting each variable separately. And it really isn't that hard to format each variable in one line of code.
format a--f 10.2;
In fact, in my opinion, rounding the values is a poor decision, if there are additional calculations that will be performed on this data.
Which brings up the question ... why do you ask? What is the reason for either rounding them all or formatting them all?
@SASuserlot wrote:
Is it possible to convert them to same number of digits after decimal in one attempt by ROUNDING the digits, instead of applying the format each variable separately.
You could round the values one variable at a time, I don't see how that's any better than formatting each variable separately. And it really isn't that hard to format each variable in one line of code.
format a--f 10.2;
In fact, in my opinion, rounding the values is a poor decision, if there are additional calculations that will be performed on this data.
Which brings up the question ... why do you ask? What is the reason for either rounding them all or formatting them all?
Thank you so much. Yes agree with you, in case if any additional calculations. In my case, these numbers at the end of all the calculations . Thanks again.
ALL numeric variables use the list word _numeric_.
Format _numeric_ f8.1
Actual round isn't much harder:
data new; set old; array _nn (*) _numeric_; do i=1 to dim (_nn); _nn[i] = round(_nn[i], 0.1); end; drop i; run;
make sure to pick an array name that doesn't duplicate that of an existing variable.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.