proc means data=test noprint;
where Married eq 'Y';
class Married Divorced6 BirthYear;
var work;
output out=test_sum(drop=_type_ _freq_)
n=n
mean=mean;
run;
data test_sum_needed;
set test_sum;
where Married ne ' ';
if BirthYear eq ' ' then BirthYear='total'; /* total sorts after years */
else;
if Divorced6 eq ' ' then Divorced6='Z'; /* Z sorts after Y and N */
else;
run;
proc sort data=test_sum_needed;
by BirthYear Married Divorced6;
run;
data test_final1;
set test_sum_needed;
by BirthYear;
retain count_No Mean_NO count_Yes Mean_Yes totalcount_Yes totalMean_Yes;
array rest(6) count_No Mean_NO count_Yes Mean_Yes totalcount_Yes
totalMean_Yes;
if first.BirthYear then do i = 1 to 6 by 1;
rest(i) = .;
end;
else;
if Divorced6 eq 'N' then do;
count_No = n;
Mean_No = mean;
end;
else if Divorced6 eq 'Y' then do;
count_Yes = n;
Mean_Yes = mean;
end;
else if Divorced6 = 'Z' then do;
totalcount_Yes = n;
totalMean_Yes = mean;
end;
else;
if last.BirthYear then output;
else;
drop Married Divorced6 n mean i;
run;
proc print data=test_final1;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.