Help using Base SAS procedures

How to quick check how many YES in the tables.

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 16
Accepted Solution

How to quick check how many YES in the tables.

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,


Accepted Solutions
Solution
‎12-05-2014 04:40 PM
PROC Star
Posts: 7,474

Re: How to quick check how many YES in the tables.

Posted in reply to lovedieer

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


All Replies
Trusted Advisor
Posts: 1,228

Re: How to quick check how many YES in the tables.

Posted in reply to lovedieer

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;

Occasional Contributor
Posts: 16

Re: How to quick check how many YES in the tables.

Thanks. that works well.

Solution
‎12-05-2014 04:40 PM
PROC Star
Posts: 7,474

Re: How to quick check how many YES in the tables.

Posted in reply to lovedieer

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;

Occasional Contributor
Posts: 16

Re: How to quick check how many YES in the tables.

Cool!. that's easy.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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