## way to calculate the porcentage n(x,x) in transpose table

Solved
Super Contributor
Posts: 301

# way to calculate the porcentage n(x,x) in transpose table

Hi to everybody,

I try to understand the final code of table 3 to understand the porcentage,

the code use a condition  n(_1,t1)=.2 then.... , please check below the right expression,

but I would like to understand this " if condition n(_1,t1)=2 ", why 2?...and how can I found it in the SAS biobiography.

Here you are the code below, please run the code, and I want to understand  the if condition n in (data total3), the way to calculate the porcentagey to calculate the:

data new;

input subjid trt fday  tday;

datalines;

1  1 1 5

2  1 . 4

2  1 . 3

3  1 1 -4

3  2 1 5

4  2 1 2

4  1 1 5

;

run;

proc sql;

create table total as

select count(distinct subjid) as n, trt 'Treatment', 'number of subjects A' as col0

from new

where fday ne .

group by trt;

quit;

proc transpose data=total out=totalt;

by col0;

id trt;

var n;

run;

proc sql;

create table total2 as

select count(distinct subjid) as n, trt 'Treatment', 'number of subjects B' as col0

from new

where fday ne . and tday le  0

group by trt;

quit;

proc transpose data=total2 out=total2t;

by col0;

id trt;

var n;

run;

data total3;

length trt1 trt2 \$12;

merge totalt (rename=(_1=t1 _2=t2)) total2t;

if n(_1,t1)=2 then trt1=put(_1,3.)||'

('||put((100*(_1/t1)),5.2)||'%)';

else trt1='  0';

if n(_2,t2)=2 then trt2=put(_2,3.)||'

('||put((100*(_2/t2)),5.2)||'%)';

else trt2='  0';

run;

Accepted Solutions
Solution
‎06-08-2012 08:03 PM
Super User
Posts: 8,093

## Re: way to calculate the porcentage n(x,x) in transpose table

The N() function counts the number of non missing arguments. So N(_1,t1) is testing that both the _1 and T1 variables are not missing.

It appears to be using this to decide whether to generate count and percentage or just to display a zero.

All Replies
Solution
‎06-08-2012 08:03 PM
Super User
Posts: 8,093

## Re: way to calculate the porcentage n(x,x) in transpose table

The N() function counts the number of non missing arguments. So N(_1,t1) is testing that both the _1 and T1 variables are not missing.

It appears to be using this to decide whether to generate count and percentage or just to display a zero.

Super Contributor
Posts: 301

## Re: way to calculate the porcentage n(x,x) in transpose table

Thank you very much Tom.

🔒 This topic is solved and locked.