I would like to point out that rarely do I think it is worthwhile to combine numbers and percents into one text string — like 15(100%) — as you have done. Even if you have an absolute unyielding requirement to make the output look like table B, working hard to generate table A is the xy problem, it gets you somewhere, but not in a direction that gets you easily to your final destination.
One idea is to simply give up the fact that you want percents in parentheses in a text string, and do as I do, create a column in a table with the count and then the next column contains the percent. And if necessary you could simply try to talk people out of having number and percent in parentheses in a text string, and point out that this is the same information, but presented in an easier to read (and easier to create) format.
If it is an absolute requirement that the table look exactly like Table B, you should still skip table A, go back to the raw data and use the %TABLEN macro.
So A looks like it could be a dataset. Perhaps something like this:
data a;
infile cards dsd dlm='|';
input Gender :$7. active :$20. placebo :$20.;
cards;
Male |15(100%)|13(100%)
Female|15(100%)|13(100%)
;
But B does not look like a dataset. What are the variable names?
Do you want to generate a REPORT that looks like that? If so why not generate the report from the dataset you used to generate A and just skip dataset A.
This is my code below and how I arrived at table A;
Please post an example for dataset dmx1_dmy1. Use a DATA step with DATALINES, so we can quickly recreate your dataset in our environment..
Thank you.
data dm;
input pat active $gender age placebo;
datalines;
101 . Male 37 0
102 1 Female 40 .
103 1 Male 50 .
104 . Female 60 0
run;
Gender was initially 1 and 2, I formated it to male and female.
dmx1_dmy1 appear like this;
Pat Active Gender Age Placebo
101 . Male 37 0
102 1 Female 40 .
103 1 Male 50 .
104 . Female 60 .
Thank you.
data dm;
input pat active $gender age placebo;
datalines;
101 . Male 37 0
102 1 Female 40 .
103 1 Male 50 .
104 . Female 60 0
;
run;
Gender was initially 1 and 2, I formated it to male and female.
dmx1_dmy1 appear like this;
Pat Active Gender Age Placebo
101 . Male 37 0
102 1 Female 40 .
103 1 Male 50 .
104 . Female 60 0
Hi,
Looks like you need a report, not a dataset. As @Tom suggested above, you could skip all data steps and use Proc Report.
Example;
data dm1;
set dm;
order=1;
run;
proc report data=dm1 out=have(drop= order _:);
column gender active placebo order;
define gender/'' display;
define active/display;
define placebo/display;
define order/order noprint;
compute before order;
line @1 text $20.;
if order=1 then text= "Gender";
endcomp;
run;
The output
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!
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.