01-14-2016 11:21 AM
I am Shriram from Bangalore, India. I am new to this community/forum. I have just about started learning SAS and have lots of doubts.
I would be glad and grateful if anyone can give me pointers on how to approach the subject, how to ask mny questions and any other suggestions.
Heres is to a start of our association:
Scenario 1: No problems and it works fine
y=round(x,0.1); /* nth decimal place*/
z=round(x,100); /* nearest 100 place*/
m=round(x,10); /*nearest 10 place*/
Scenario 2: how to round of columns of an incoming data set
then how to write the code for rounding of columns y w r l and k. (Attached screen shot of columns)
the data comprises of columns y w r l and K and year. Now all these columns(except year) are in 8-9th decimal place. I want to round of to the first decimal place?...
01-14-2016 11:48 AM
To me, the most important piece of advice is not to round unless you absolutely have to. You can control how many decimal places to use when printing by applying a format. For example:
proc print data=test;
format y 8.1;
format z 8.2;
You can let variables keep their actual value without rounding, but still print rounded versions.
01-14-2016 12:04 PM
@Astounding - Thank you. Yes I agree with you.
Please guide me on this:
You have used 8.1 and 8.2 - this is new to me, as in I was not aware there were number formats like 8.1...
How do i learn short cuts like that - as in can you share a link or something or am i approaching this the right way?
Hope my question makes sense!
01-14-2016 12:11 PM
@Astounding or if i were to rephrase my earlier question
Can you also explain (lead to to the explanation link) how this works?
As in if i use format 1.1 or 2.1 or ......8.1.... etc
What is the difference or what is the logis used by sas to apply these formats onto the dataset?
01-14-2016 12:32 PM - edited 01-14-2016 01:44 PM
The "logic" for applying formats depends on what you are doing. Many analysis procedures will have a default to display a given number of decimals but you can direct the output to a data set and print the results with a different number of decimals, or you may be able to override the default. Here is an example:
proc tabulate data=sashelp.class; class sex; var height weight; table sex, (height weight)*(n mean std) /box='Default formats for statistics'; table sex, (height weight)*(n mean*f=f8.4 std*f=best12.) /box='Specified formats for statistics'; run;
You can also use formats to group data
Proc freq data=sashelp.class; tables weight; run; proc format library=work; value WeightGroup 0 - 85 = ' 0 <= 85' 85< - 110= '85 <=110' 110< - high='110>'; run; Proc freq data=sashelp.class; tables weight; format weight WeightGroup.; run;
01-14-2016 12:55 PM
There are dozens of numeric formats available within the software.
It isn't a question of explaining a few tricks. Formatting is one of the basics. Just start somewhere, and add to what you know over time.
To explain 8.1 and 8.2, here are a few general rules. The first number ("8" in this case) refers to the total number of positions being used to print a numerical value. That includes all digits (whether before or after the decimal point), the decimal point, and (if needed) a negative sign. If you are using other numeric formats, such as those that print a dollar sign or a comma, the first number still includes every character being printed. The second number ("1" or "2" in this case) is the number of digits to print after the decimal point. SAS will automatically round as needed.
If you apply a format when reporting, it does not change the data. It only changes the form in which that report prints the data.
Hope this helps!
01-14-2016 01:12 PM
01-14-2016 01:17 PM
Truthfully, it's just coincidence that numbers are stored in 8 bytes. SAS stores the value (not the digits themselves) in a totally different form (binary floating point). SAS can accurately store an integer with 15 to 16 significant digits (depends on the operating system). Very similar explanations would apply to other numeric formats (whether longer or shorter): comma14.2, dollar5.0, for example.
Need further help from the community? Please ask a new question.