I have a table with 20 column as flags, their value are Y or N, I want to check how many Y for each records, beside change all Y to 1 and N to 0 and then do the sum, is there any quick way to do sum or count how many Y for each record?
Thanks,
Here is a way that takes a bit less code:
data have;
input (x1-x7 y1-y7 z1-z6) ($);
cards;
Y N Y N Y N Y N Y N Y N Y N Y N Y N Y N
N N N Y Y N N N Y Y N N N N N N N N N N
;
data want;
set have;
total=countc(catt(of x1--z6),'Y');
run;
data want;
set have;
array q{*} q1-q20;
array q_num{20};
cnt_Y=0;
do i=1 to dim(q);
if q{i}='Y' then q_num{i}=1;
else q_num{i}=0;
end;
do i=1 to dim(q);
if q{i}='Y' then cnt_Y+1;
end;
run;
Thanks. that works well.
Here is a way that takes a bit less code:
data have;
input (x1-x7 y1-y7 z1-z6) ($);
cards;
Y N Y N Y N Y N Y N Y N Y N Y N Y N Y N
N N N Y Y N N N Y Y N N N N N N N N N N
;
data want;
set have;
total=countc(catt(of x1--z6),'Y');
run;
Cool!. that's easy.
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.