- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;