Help using Base SAS procedures

How to keep the last "0" in a string?

Reply
Frequent Contributor
Posts: 128

How to keep the last "0" in a string?

Hi everyone,

I was creating a statistical report and wanted to have a p-value with 3 digits.

I got p=0.0501, but if I rounded it to 0.001 then I would have a p=0.05. How can I keep the last zero?

I used compress or compbl to make it into a string, but they did not work.

Any suggestions?

Thanks.

Respected Advisor
Posts: 3,799

Re: How to keep the last "0" in a string?

17         data _null_;
18            p=0.0501;
19            put p=pvalue5.3;
20            run;

p=
0.050
Frequent Contributor
Posts: 128

Re: How to keep the last "0" in a string?

Posted in reply to data_null__

@data_null and @ballardw, thanks for the quick reply!

Just one more question. If I want to put "0.050" in a string, for example I may try to use "call symput" to make a &pvalue=0.050, then how can I do?

Thanks again!

Respected Advisor
Posts: 3,799

Re: How to keep the last "0" in a string?

PUT function

Super User
Posts: 11,343

Re: How to keep the last "0" in a string?

For most purposes assigning a format with the appropriate number of decimal points will display as you want. I would suggest an f5.3. The internal storage of the value doesn't change just the display.

An example:

data _null_;  

file print;  

x = 0.05;  

put x f6.3;

run;

Ask a Question
Discussion stats
  • 4 replies
  • 145 views
  • 0 likes
  • 3 in conversation