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

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,

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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;

View solution in original post

4 REPLIES 4
stat_sas
Ammonite | Level 13

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;

lovedieer
Calcite | Level 5

Thanks. that works well.

art297
Opal | Level 21

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;

lovedieer
Calcite | Level 5

Cool!. that's easy.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 963 views
  • 3 likes
  • 3 in conversation