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

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.

Thanks in advance. V

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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.

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

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.

michtka
Fluorite | Level 6

Thank you very much Tom.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1524 views
  • 0 likes
  • 2 in conversation