BookmarkSubscribeRSS Feed
Hani18
Calcite | Level 5

hey friends, I've been stuck on the problem. can someone please help me with this 

Information on presence or absence (yes or no) of two characteristics A and B is available for several individuals.

ID A B
217 no no
229 no yes
156 yes no
205 yes no
178 no yes
101 yes yes
112 no no
222 no yes
105 yes yes
144 no no
211 yes yes
244 no yes
139 yes yes
166 no no
109 yes yes
178 no yes
243 yes yes
219 no no
113 yes yes
194 no yes

 

Compute the number of individuals who have

(a) characteristic A

(b) characteristic B

(c) only characteristic A

(d) only characteristic B

(e) both characteristics

(f) neither characteristic

(g) either characteristic

3 REPLIES 3
japelin
Rhodochrosite | Level 12

Please include appropriate words in the title.

The sample code is given below.
For the rest, please think a little on your own.

 

 

data have;
length id 8 a $3 b $3;
input id a b;
datalines;
217 no no
229 no yes
156 yes no
205 yes no
178 no yes
101 yes yes
112 no no
222 no yes
105 yes yes
144 no no
211 yes yes
244 no yes
139 yes yes
166 no no
109 yes yes
178 no yes
243 yes yes
219 no no
113 yes yes
194 no yes
run;

data want_a;
  set have;
  where a='yes';
run;
data want_c;
  set have;
  where a='yes' and b='no';
run;
whymath
Lapis Lazuli | Level 10
data have;
  input ID$ A$ B$;
  cards;
217 no no
229 no yes
156 yes no
205 yes no
178 no yes
101 yes yes
112 no no
222 no yes
105 yes yes
144 no no
211 yes yes
244 no yes
139 yes yes
166 no no
109 yes yes
178 no yes
243 yes yes
219 no no
113 yes yes
194 no yes
;
run;

data want;
  set have end = eof;
    
  _A + (A = 'yes');
  _B + (B = 'yes');
  _C + (A = 'yes' and B ^= 'yes');
  _D + (B = 'yes' and A ^= 'yes');
  _E + (A = 'yes' and B = 'yes');
  _F + (A ^= 'yes' and B ^= 'yes');
  _G + (A = 'yes' or B = 'yes');
  if eof;

  put (_A _B _C _D _E _F _G) (=);
run;
_A=9 _B=13 _C=2 _D=6 _E=7 _F=5 _G=15

It is a very basic question, I really recommend you to learn <The little SAS book> immediately.

Reeza
Super User

FYI - I've updated your subject line of the question to make it more related to your question otherwise every question on here would have the same title.

This question is testing your knowledge of AND/OR logic.
An IF/WHERE statement would be the most likely solution here.

 


@Hani18 wrote:

hey friends, I've been stuck on the problem. can someone please help me with this 

Information on presence or absence (yes or no) of two characteristics A and B is available for several individuals.

ID A B
217 no no
229 no yes
156 yes no
205 yes no
178 no yes
101 yes yes
112 no no
222 no yes
105 yes yes
144 no no
211 yes yes
244 no yes
139 yes yes
166 no no
109 yes yes
178 no yes
243 yes yes
219 no no
113 yes yes
194 no yes

 

Compute the number of individuals who have

(a) characteristic A

(b) characteristic B

(c) only characteristic A

(d) only characteristic B

(e) both characteristics

(f) neither characteristic

(g) either characteristic


 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 623 views
  • 1 like
  • 4 in conversation