BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Wolverine
Pyrite | Level 9

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
PaigeMiller
Diamond | Level 26

Use the PUT function

 

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

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Use the PUT function

 

Final_output = COMPRESS(put(MeanRD,8.2)||"("||put(StdRD,8.2)||")");
--
Paige Miller
PaigeMiller
Diamond | Level 26

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
ballardw
Super User

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.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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