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-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!

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.

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
  • 3 replies
  • 447 views
  • 1 like
  • 4 in conversation