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

Hi everyone,

 

I have a mean, lower CI variable and upper CI variable. I would like the combine them into one variable. The issue is the CI variable has a long decimal trail. I would like to limit it to two decimals after using the Cat function. So here is my code currently:

 

data have;
input Mean  :  lowerCLmean : upperCLmean;
cards;
45               30.123456                         50.789123
20               15.789123                         30.123456

;

data want;
set have;
new=cat(mean,' (',lowerclmean,'-',upperclmean,')');

proc print;run;
 
What I really want:

Obs Mean lowerCLmean upperCLmean Really Want
22015.789130.123520 (15.78-30.12)

 

 

Thanks in advance! 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

data want;
set have;
new=cat(mean,' (',put(lowerclmean,f5.2 -L),'-',put(upperclmean,F5.2 -L),')');

 

You can nest all sorts of functions inside the cat, cats, catt, catx etc. functions as long as the results are strings.

View solution in original post

3 REPLIES 3
ballardw
Super User

data want;
set have;
new=cat(mean,' (',put(lowerclmean,f5.2 -L),'-',put(upperclmean,F5.2 -L),')');

 

You can nest all sorts of functions inside the cat, cats, catt, catx etc. functions as long as the results are strings.

hwangnyc
Quartz | Level 8

Thank you Ballard! Can you tell me what the  "-L" does?

ballardw
Super User

The -L left justifies the result. if your value were actually 9.33 without the -L there would be a leading space as the F5.2 format will display the result in 5 columns and right justified by default: " 9.33" . Since it appeared that you did not want the CI to look like ( 9.33-12.75) for example I used that option.

 

Character formats will default to left justification but if you want right justification when using Put with a character format you could use put(somevar,$charfmt. -R) which may appear better for some table row headers or graph axis values.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 3 replies
  • 2533 views
  • 4 likes
  • 2 in conversation