BookmarkSubscribeRSS Feed
MBI
Calcite | Level 5 MBI
Calcite | Level 5
Hi all,

I'm about to lose my mind over this one. I have a list of weights that I want to change the number format on.

weight1
-----------
37.49542962
35.5862069
36.41153082
27.3943662
39.19298246
30.84396467
21.29032258
31.898055
26.21052632
31.80722892
30.3030303
34.17582418
45.52
30.25423729
32.86206897

When I try to convert it using the 'input' function ...
weight2 = input(weight1, 5.);
some of the values are changed to null!

weight2
-----------
37.49
35.58
36.41
27.39
39.19
30.84
21.29
31.89
26.21
31.8
30.3
34.17
.
30.25
32.86

Why is this one value converted to null? The numbers in 'weight1' are formatted as numeric. I can't think of what is going on here. Is there a better way to do this?

Thanks!

MBI
2 REPLIES 2
Cynthia_sas
SAS Super FREQ
Hi:
Generally, you use the INPUT function to convert a CHARACTER variable to a NUMERIC variable. If your WEIGHT1 var is numeric, then I'm surprised that you didn't report a NOTE
in the log like this:[pre]

NOTE: Numeric values have been converted to character
values at the places given by: (Line):(Column).
xxx:yy
[/pre]
(where the line:column numbers point to the line that contains the INPUT function.)
I would not use the INPUT function since WEIGHT1 is numeric. It's the wrong function.

A number can have great precision when stored, for calculation purposes -- but you might only want to display 2 decimal places, for report purposes.
You can assign a SAS Format on a procedure by procedure basis -- you want WEIGHT1 formatted as 5.2 for one proc print, but want it formatted as 11.6 for a different proc print.
OR you can have the format assigned permanently so that the default format would always be used for the display of the number.
Using a SAS Format to change the DISPLAY of the number doesn't change the internal STORAGE of the number.

[pre]
format weight1 5.2;
format weight1 11.8;
format weight1 11.6;
format weight1 5.1;
[/pre]

These are all FORMAT statements that you could use with your procedures to change the DISPLAY of WEIGHT1.

Anyway back to the idea of storing a number with 2 decimal places versus displaying a number with 2 decimal places. The above statements only DISPLAY a number with 2 decimal places. They do nothing to adjust the decimal places for the internal storage of the number. But perhaps, you want to change weight1 so it's only STORED with 2 decimal places -- in which case, the ROUND or ROUNDZ functions might be what you want to use.

What is it that you're trying to do?

Do you want to just DISPLAY WEIGHT1 with 2 decimal places on reports?
(Use a FORMAT statement)
[pre]
format weight1 5.2;
[/pre]
or
Do you want to use WEIGHT1 with 2 decimal places in calculations (instead of all 8 possible decimal places)?
(ROUND WEIGHT1 before you use it in the calc):
[pre]
somecalc = round(weight1,.01) * 4;
sillycalc = (round(weight1,.01) / height) * 14;
[/pre]

or
Do you want to keep WEIGHT1 as the original number, but make a second variable (WEIGHT2) that is STORED with 2 decimal places?
[pre]
weight2 = round(weight1,.01);
[/pre]

You might also want to read some Tech Support documents that talk about numeric precision:
http://support.sas.com/techsup/technote/ts654.pdf
http://support.sas.com/documentation/cdl/en/lrcon/59522/HTML/default/a000695157.htm

If you need more help figuring out what you want to do with your numbers, and/or need help figuring out whether your particular analysis would be affected by the number of decimal places, you might consider contacting Tech Support for more help. If all you want to do is change the DISPLAY of WEIGHT1 in a report, then a simple FORMAT statement should work for you.

cynthia
MBI
Calcite | Level 5 MBI
Calcite | Level 5
Cynthia,

Thank you very much. Your suggestion of round(weight1,.01) worked great. I wasn't expecting nearly as detailed a response as your provided!

-MBI

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1240 views
  • 0 likes
  • 2 in conversation