data dec;
input catn score1 score2 ;
cards;
1 7.4245 4.123
3 6.4243 4.243
7 4.7653 7.653
11 5.2556 2.556
6 5.3411 3.411
8 5.0046 0.046
7 3.9589 9.589
99 5.1905 1.905
;
run;
data dec1;
set dec;
array x(2) score1 score2;
do i = 1 to 2 by 1;
x(i) = round(x(i),0.01);
end;
drop i;
run;
I would like to know how I can achieve the same results using the Numeric formats like 6.2 or 8.2 formats.
Also is it possible dynamically control the digits after decimal based on my requirement.
for example I want to round/format the data one digit after decimal less than the actual data?
Thank you for your suggestions.
I would like to know how I can achieve the same results using the Numeric formats like 6.2 or 8.2 formats.
format score1 8.4 score2 7.3;
Also is it possible dynamically control the digits after decimal based on my requirement.
for example I want to round/format the data one digit after decimal less than the actual data?
Please give example of the desired output.
like
score1 score2
7.4245 4.123
First observation have 4 digits after decimal . I want dynamically identify how many digits available after decimal in score1 and score 2 instead of looking into the data separately . Then output the the values one digits less than that after decimal.
ex:
score1 have 7.4245---> want 7.424
score2 have 4.123---> want 4.12
Thanks
I have a lot of questions here.
Please answer all 4 questions.
So starting with #4, you want some formatting on a report. Are there so many variables (your example has just 2 but I am assuming the real world problem has more) that you need the SAS program to figure it out? Because, the simplest solution to me would be to have a human say column 1 needs 4 digits, and column 2 needs 3 digits and so on. To be honest, since you originally asked the question, I have tried to think of a way to have the computer figure out how many places after the decimal there are, and I have decided its either difficult or impossible (although I'm sure someone will come along with an ingenious solution) and simply much easier for a human to look at the data and determine digits than for some human to write code for this.
Thanks you so much your answer. I really appreciate for your time.
Yes, you can make a dynamic format. For example, you have a number 7.4245. It uses six spaces including one for the decimal point and has 4 digits after the decimal point. Therefore, the format that would fit that number perfectly is 6.4. If you want to round it dynamically to one digit less than the last where the last digit can be any location, like 7.42455555…, you would need to specify the format &mvar_a.&mvar_b using variables a and b and putting them into macro variables mvar_a and mvar_b:
a = length(number)
b = length(substring(number, index(‘.’)) minus however many digits you would like to hide
Call symputx(mvar_a, “a”);
Call symputx(mvar_b, “b”);
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.