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;
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.
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.
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.