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

Hello everyone, 

 

My data table looks like this: 

order

gender

count1

percent1

count2

percent2

1

MALE

191,404

85.6%

22,320

87.7%

2

FEMALE

23,349

10.4%

2,995

11.8%

3

MISSING

8,861

4.0%

132

0.5%

 

However, I would like to combine the count variables with the percent variables 

to get the table to look like this: 

order

gender

count1

count2

1

MALE

191,404(85.6%)

22,320(87.7%)

2

FEMALE

23,349(10.4%)

2,995(11.8%)

3

MISSING

8,861(4.0%)

132 (0.5%)

 

I searched this site and found two codes that will combine the variables and they are:

Test=CAT(strip(date),'(',strip(Devdate),')');

Test2=compress(date||"("||Devdate||")");

 

They work but my formats will not stay and the data looks like this:

test

22320(0.8771171454)

2995(0.1176956026)

132(0.0051872519)

 

My question is does anyone know how I can combine the columns and keep the formats? And if possible, can I do

this using Proc Sql? If not, I can also use a data step.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

The CAT... series of functions will convert numbers to strings for you, but they ignore any formats that might be attached.   You can use the VVALUE() function to retrieve the formatted value or a variable.

data want;
  set have;
  length new_count1 new_count2 $30 ;
  new_count1=cats(vvalue(count1),'(',vvalue(percent1),')');
  new_count2=cats(vvalue(count2),'(',vvalue(percent2),')');
run;

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

The CAT() function does not know what format you would like. You have to tell it

 

test=cats(put(count1,comma8.0),'(',put(percent1(percent6.1),')');

Also, all of this can be done in SQL or in a DATA step, whichever you please.

--
Paige Miller
Tom
Super User Tom
Super User

The CAT... series of functions will convert numbers to strings for you, but they ignore any formats that might be attached.   You can use the VVALUE() function to retrieve the formatted value or a variable.

data want;
  set have;
  length new_count1 new_count2 $30 ;
  new_count1=cats(vvalue(count1),'(',vvalue(percent1),')');
  new_count2=cats(vvalue(count2),'(',vvalue(percent2),')');
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 1743 views
  • 4 likes
  • 3 in conversation