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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.