BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ameurgen
Obsidian | Level 7

Hi every one,

below is type of data i am working on, and i need a little help , in fact i need to count or extract the animals those have only observation recorded  from BHb Var. or recorded from two Var. BHB and MUn and also , three Var. BHB, MUN and Lac , same thing if an animal have only one observation fr only the 3rd var (LAc.

Thank guys , i appriciate your help.

 

 

Animal  BHB MUN Lac
1 1 4  
2 1   5
3 1 4 5
4 1 4 5
5   4  
6 1 4 5
7     5
8 1 4 5
9   4 5
10 1   5
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Colors are hard to program.  But numbers are easy.

data have;
  input Animal BHB MUN Lac;
cards;
1  1 4 . 
2  1 . 5
3  1 4 5
4  1 4 5
5  . 4 .
6  1 4 5
7  . . 5
8  1 4 5
9  . 4 5
10 1 . 5
;

data want;
  set have;
  group = 4*missing(BHB)+2*missing(MUN)+missing(Lac);
run;

Result

Obs    Animal    BHB    MUN    Lac    group

  1       1       1      4      .       1
  2       2       1      .      5       2
  3       3       1      4      5       0
  4       4       1      4      5       0
  5       5       .      4      .       5
  6       6       1      4      5       0
  7       7       .      .      5       6
  8       8       1      4      5       0
  9       9       .      4      5       4
 10      10       1      .      5       2

Or use the BINARY format to see how the numbers 0 to 7 are formed from the three bits.

proc print;
  format group binary3.;
run;
Obs    Animal    BHB    MUN    Lac    group

  1       1       1      4      .      001
  2       2       1      .      5      010
  3       3       1      4      5      000
  4       4       1      4      5      000
  5       5       .      4      .      101
  6       6       1      4      5      000
  7       7       .      .      5      110
  8       8       1      4      5      000
  9       9       .      4      5      100
 10      10       1      .      5      010

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

Please show us the desired output from this example data set.

 

 

--
Paige Miller
Ameurgen
Obsidian | Level 7

Hi Mr. Paige Miller

i need to identify each animal with each test are BHB , MUN or Lac, for example, following the type of color, animal 3 , 4 , 6 and 8  have the complete 3 tests. but 2 and 10 are tested only by BHB and lac. 

So, i dont know if you have now an idea about my my desirable output data.

Thank you so much for your help.

 

AMEUR

 

 

Ameurgen_0-1688473302169.png

 

PaigeMiller
Diamond | Level 26
data want;
    set have;
    category = n(bhb,mun,lac);
run;
--
Paige Miller
Ameurgen
Obsidian | Level 7

Hi , Paige  Miller , thank you for your reply.

Sorry its not working this give the whole number of tests without specify which test , for example using the table mentionned above, those animals have only two different test type . the code give me number 2 but i cant know which test is BHB with Lac or BHB with MUN.

Thank you so muhc

 

AMEUR

Tom
Super User Tom
Super User

Colors are hard to program.  But numbers are easy.

data have;
  input Animal BHB MUN Lac;
cards;
1  1 4 . 
2  1 . 5
3  1 4 5
4  1 4 5
5  . 4 .
6  1 4 5
7  . . 5
8  1 4 5
9  . 4 5
10 1 . 5
;

data want;
  set have;
  group = 4*missing(BHB)+2*missing(MUN)+missing(Lac);
run;

Result

Obs    Animal    BHB    MUN    Lac    group

  1       1       1      4      .       1
  2       2       1      .      5       2
  3       3       1      4      5       0
  4       4       1      4      5       0
  5       5       .      4      .       5
  6       6       1      4      5       0
  7       7       .      .      5       6
  8       8       1      4      5       0
  9       9       .      4      5       4
 10      10       1      .      5       2

Or use the BINARY format to see how the numbers 0 to 7 are formed from the three bits.

proc print;
  format group binary3.;
run;
Obs    Animal    BHB    MUN    Lac    group

  1       1       1      4      .      001
  2       2       1      .      5      010
  3       3       1      4      5      000
  4       4       1      4      5      000
  5       5       .      4      .      101
  6       6       1      4      5      000
  7       7       .      .      5      110
  8       8       1      4      5      000
  9       9       .      4      5      100
 10      10       1      .      5      010

Ameurgen
Obsidian | Level 7

Its worked , perfectly , thank you TOM.

AMEUR

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
  • 6 replies
  • 490 views
  • 0 likes
  • 3 in conversation