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

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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

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