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

Dear all

I’ve a dataset with a binary variable named ‘Healthy’ (values Yes, No) and a stratification variable named “Treatment”  (values A, B).

To report the percentage of Healthy*Treatment I’m using a PROC TABULATE and the output is:

                      Treatment                   Total

Healthy            A                  B          

                  N    %            N    %           N    %

Yes            xx    xx.x%     xx   xx.x        xx   xx.x

No             xx    xx.x%     xx   xx.x        xx   xx.x

Total         xx   xx.x%       xx   xx.x%     xx   xx.x%

I would like to report only the occurrence Helthy=Yes (N and %) with a PROC REPORT. Is it possible? How can I do it?

Thanks in advance for any help

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

I thought that might be your next question. :smileyshocked:  You may need to transpose your data to get this question response format but that would best suite PROC REPORT.  You will also need to address the order of the questions, as I'm sure that will be an issue. 

proc plan seed=340564315;

   factors subjid=40 ordered trt=1 of 2 question=2 ordered resp=1 of 2 / noprint;

   output out=binary question cvals=('Healthy' 'Emerg') resp nvals=(0 1);

   run;

   quit;

proc print;

   run;

proc report data=binary nowd list headline;

   columns question trt, (resp=hsum resp=hmean) ('Total' '--'  resp=hsum2 resp=hmean2);

   define question / group width=10;

   define hsum / sum '--' 'N' format=5.;

   define hmean / mean '--' '%' format=percentn7.1;

   define hsum2  / sum 'N' format=5.;

   define hmean2 / mean '%' format=percentn7.1;

   define trt / across format=1. 'Treatment' '--';

   run;

View solution in original post

9 REPLIES 9
data_null__
Jade | Level 19

For binary (0,1) variable SUM=N of 1s.  Mean=proportion of 1s.  This code may be helpful.

proc plan seed=340564315;

   factors subjid=40 ordered healthy=1 of 2 / noprint;

   treatments trt=2;

   output out=binary healthy nvals=(0 1);

   run;

   quit;

proc print;

   run;

proc report data=binary nowd list headline;

   columns trt, (healthy=hsum healthy=hmean) ('Total' '--'  healthy=hsum2 healthy=hmean2);

   define hsum / sum '--' 'N' format=5.;

   define hmean / mean '--' '%' format=percent7.1;

   define hsum2  / sum 'N' format=5.;

   define hmean2 / mean '%' format=percent7.1;

   define trt / across format=1. 'Treatment' '--';

   run;

Ksharp
Super User

You can do it by using data set option where=:

proc tabulate data=binary(where=(Helthy='Yes'));

proc report also can do it easily. If you can post some sample data.

Or Null's code maybe is what you want.

Ksharp

L_L
Calcite | Level 5 L_L
Calcite | Level 5

I' m sorry I was not accurate

Sample data:

data demog;  infile cards;

input patid $1-3 treat $5 healthy $7-9 Emerg $11-13;

cards;

001 A Yes No

002 B No  No

003 A No  Yes

004 B Yes Yes

005 A No  Yes

;

run;

I would like to report only the occurrence Helthy=Yes (N and %) and Emerg=Yes (N and %) in the same table.. I think by proc tabulate is not possible. What about using the proc report?Thank in advance

Ksharp
Super User

What is your ouput destionation? listing PDF?

Maybe you can set the color of font white (as the same with your background).

Such as style={foreground=white}

If you do not want this, then It will be more complicated.

data demog; 
infile datalines;
input patid  $  treat $ 5 healthy $ 7-9 Emerg $ 11-13;
datalines;
001 A Yes No
002 B No  No
003 A No  Yes
004 B Yes Yes
005 A No  Yes
;
run;
options missing=' ';
proc report data=demog nowd out=test;
column healthy _heal treat,(n pctn _n _pctn) ;
define healthy /group noprint;
define _heal/computed "Healthy";
define treat/across ;
define n /noprint;
define pctn/noprint;
define _n/computed format=best8.;
define _pctn/computed format=percent8.2;
compute _heal/character length=4 ;
 if healthy='Yes' then _heal=healthy;
  else _heal=' ';
endcomp;
compute _n;
 if healthy='Yes' then do;_c5_=_c3_; _c6_=_c4_;end;
  else do; _c5_=.; _c4_=.;end;
endcomp;
compute _pctn;
   if healthy='Yes' then do;_c9_=_c7_; _c10_=_c8_;end;
  else do; _c9_=.; _c10_=.;end;
endcomp;
 

run;

Ksharp

L_L
Calcite | Level 5 L_L
Calcite | Level 5

Thank you so much

Destination output is rtf file

The code is perfect for one variable (ex. Healthy).

Is it possible to have a table with two or more variable as the table below?

                                   

Healthy                   A                              B

Yes                      xx  (xx.x%)                 xx (xx.x%)

Emerg

Yes                     xx (xx.x%)                   xx (xx.x%)

data_null__
Jade | Level 19

I thought that might be your next question. :smileyshocked:  You may need to transpose your data to get this question response format but that would best suite PROC REPORT.  You will also need to address the order of the questions, as I'm sure that will be an issue. 

proc plan seed=340564315;

   factors subjid=40 ordered trt=1 of 2 question=2 ordered resp=1 of 2 / noprint;

   output out=binary question cvals=('Healthy' 'Emerg') resp nvals=(0 1);

   run;

   quit;

proc print;

   run;

proc report data=binary nowd list headline;

   columns question trt, (resp=hsum resp=hmean) ('Total' '--'  resp=hsum2 resp=hmean2);

   define question / group width=10;

   define hsum / sum '--' 'N' format=5.;

   define hmean / mean '--' '%' format=percentn7.1;

   define hsum2  / sum 'N' format=5.;

   define hmean2 / mean '%' format=percentn7.1;

   define trt / across format=1. 'Treatment' '--';

   run;

L_L
Calcite | Level 5 L_L
Calcite | Level 5

Dear data _null_

I' m sorry but I'm new in proc report..

hereafter you'll find my code (thanks to you):

data demog;

infile datalines;

input patid  $  treat $ 5 healthy $ 7-9 Emerg $ 11-13;

datalines;

001 A Yes No

002 B No  No

003 A No  Yes

004 B Yes Yes

005 A No  Yes

;

run;

data binary;
set demog;
keep patid treat healthy Emerg;
array HH [2] healthy Emerg;
do i=1 to 2;
  if HH ='Yes' then HH= 1;
  if HH ='No' then HH= 0;
end;
run;

data bin (drop=healthy Emerg);
set binary;
array HH [2] healthy Emerg;
do i=1 to 2;
hea = HH ;
output;
end;
run;

data bin (drop=hea);
set bin;
    HEAL=hea*1;
run;

proc format;
value hea       1 = 'Healthy'
                         2 = 'Emerg'     
;
run;

proc report data=bin nowd list headline;
   columns i treat,  (heal heal=h_heal);
   define i / group width=10 ' ' format= hea. order=freq left;
   define heal / sum 'N';
   define h_heal / mean '%' format=percentn7.1;
   define treat / across format=$tipo. 'Patients' '--';
  
  
run;

I would like to have a column with the 'Total' ..what's missing in the code?

Thanks very much in advanced

data_null__
Jade | Level 19

I think this address your questions.

data demog;

   infile datalines;

   input patid  $  treat $ 5 Healthy $ 7-9 Emerg $ 11-13;

   datalines;

001 A Yes No

002 B No  No

003 A No  Yes

004 B Yes Yes

005 A No  Yes

;;;;

   run;

proc freq;

   tables (healthy emerg)*treat;

   run;

proc transpose data=Demog out=binary;

   by patid treat;

   var Healthy Emerg;

   run;

data binary;

   set binary;

   resp = ifN(col1 eq: 'Y',1,0);

   run;

proc format;

   value $hea(notsorted)

      'Healthy' = 'Healthy'

      'Emerg'   = 'Emerg'  

   ;

   run;

proc report data=binary nowd list headline;

   columns _name_ treat,(resp resp=respPct) ('Total' '--' resp resp=respPct);

   define _name_ / group width=10 ' ' format= $hea. order=data left preloadfmt;

   define resp / sum 'N';

   define respPct / mean '%' format=percentn7.1;

   define treat / across /*format=$tipo.*/ 'Patients' '--';

   run;

L_L
Calcite | Level 5 L_L
Calcite | Level 5

Many thanks. It works well

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 9 replies
  • 1235 views
  • 6 likes
  • 3 in conversation