Hi eaveryone, I 've got the next dataset have, my problem is that I want to make a second query to add 2 new variables pla_total and drug_total to my first query (5 variables). But as difference for the first query (select distinct subno,trt,time) , this second query need to come from different select ( select distinct subno, trt) to summary the right number of subjects 3, and 2, rather than 6 and 4, but I dont know how to do it. data have; length sex race trt time $20; length subno weight height age 8; input subno weight height sex race age trt time; datalines; 1 63.7 141.85 Male Caucasian 19 Drug present 1 63.7 141.85 Male Caucasian 19 Drug past 2 72.6 149.22 Female Black 27 Placebo present 2 72.6 149.22 Female Black 27 Placebo past 3 60.7 147.64 Female Caucasian 26 drug present 3 60.7 147.64 Female Caucasian 26 drug past 4 64.2 150.93 Male Caucasian 21 Placebo present 4 64.2 150.93 Male Caucasian 21 Placebo past 5 60.6 153.56 Male Asian 41 drug present 5 60.6 153.56 Male Asian 41 drug past run; proc sql; create table want as *first query; select 'n subjects' as col0, sum(upcase(trt)='DRUG' and upcase(time)='PAST') as drug_past, sum(upcase(trt)='DRUG' and upcase(time)='PRESENT') as drug_present, sum(upcase(trt)='PLACEBO' and upcase(time)='PAST') as pla_past, sum(upcase(trt)='PLACEBO' and upcase(time)='PRESENT') as pla_present, *second query, where need to be created from different select, not how it is at the moment; sum(upcase(trt)='DRUG') as drug_total, sum(upcase(trt)='PLACEBO') as pla_total from (select distinct subno,trt,time from have); quit; Cheers, V.
... View more