## Rounding to 2 decimals and combining numbers such 27.00(18.70) without dropping trailing zeros

I'm trying to create a single field with the mean and standard deviation combined in mean(std) format. I have it mostly figured out, but the problem is that trailing zeros are being truncated. So rather than 27.00(18.70), it shows up as 27(18.7).  But numbers such as 14.21(15.04) show up properly.

In the code below, the zeros are already truncated in the "test" dataset. How do I add them back in? The final numbers will be exported to an Excel table, so I don't think I could just apply a format to them.

``````data test;
input Mean Std;
datalines;
14.2123	15.0416
27.0000	18.7000
27.3185	19.8000
;

data want; set test;

StdRD = ROUND(Std,.01);
MeanRD = ROUND(Mean,.01);

Final_output = COMPRESS(MeanRD||"("||StdRD||")");

RUN;``````

1 ACCEPTED SOLUTION

Accepted Solutions

## Re: Rounding to 2 decimals and combining numbers such 27.00(18.70) without dropping trailing zeros

Use the PUT function

``````Final_output = COMPRESS(put(MeanRD,8.2)||"("||put(StdRD,8.2)||")");
``````
--
Paige Miller
4 REPLIES 4

## Re: Rounding to 2 decimals and combining numbers such 27.00(18.70) without dropping trailing zeros

Use the PUT function

``````Final_output = COMPRESS(put(MeanRD,8.2)||"("||put(StdRD,8.2)||")");
``````
--
Paige Miller

## Re: Rounding to 2 decimals and combining numbers such 27.00(18.70) without dropping trailing zeros

It seems so simple now! Thanks!

## Re: Rounding to 2 decimals and combining numbers such 27.00(18.70) without dropping trailing zeros

Alternative solution using the VVALUE function

``````data want;
set test;
stdrd = round(std,.01);
meanrd = round(mean,.01);
format stdrd meanrd 8.2;
final_output = compress(vvalue(meanrd)||"("||vvalue(stdrd)||")");
run;``````
--
Paige Miller

## Re: Rounding to 2 decimals and combining numbers such 27.00(18.70) without dropping trailing zeros

Anytime SAS converts a numeric value to character, such as to concatenate the values you attempt, it uses a BEST. format which doesn't show trailing zeroes. So you use a PUT and provide a desired format so you control the conversion.

You may find the -L option with the PUT function as in Put(meadrd,8.2 -L) useful to create values without any leading spaces that require another function to remove.

Discussion stats
• 4 replies
• 133 views
• 1 like
• 3 in conversation