BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jonatan_velarde
Lapis Lazuli | Level 10

Good morning:

 

I need some help to complete this table, lets go:

 

I have this data set:

 

data have;

input Treatment repetition measure damage;

cards;

A   1   1   1

A   1   2   2

;

 

resulting in this table:

 

Treatment Repetition Measure Damage
A   1 1 1
A   1 2

3

 

The table i need to create use all the left data into each observation, as you can see, i have diferent tipe os damage, going fom "0" to "4", in the first observation, the experimental unit is associated to damage level "1", there fore this cant contain the other levels  of damage, the second observation the same way, it present damage "3", so it can't be 0, 1, 2 or 4.

 

The table i want to create should be this:

 

Treatment repetition measure damage Result
A   1 1 0 0
A   1 1 1 1
A   1 1 2 0
A   1 1 3 0
A   1 1 4 0
A   1 2 0 0
A   1 2 1 0
A   1 2 2 0
A   1 2 3 1
A   1 2 4 0

 

With this, is created the data is not in the original data set, showing that in the same measure, the experimental unit does not show the hidden information about the level of damage that is not present in the experiment.

 

Thanks for your cooperation

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

This should do it - the loop generates the 5 output rows, and compared to the original for result:

data have;
  input Treatment $ repetition measure damage;
cards;
A   1   1   1
A   1   2   2
;
run;

data want;
  set have (rename=(damage=check));
  do damage=0 to 4;
    if damage=check then result=1;
    else result=0;
    output;
  end;
run;

View solution in original post

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

This should do it - the loop generates the 5 output rows, and compared to the original for result:

data have;
  input Treatment $ repetition measure damage;
cards;
A   1   1   1
A   1   2   2
;
run;

data want;
  set have (rename=(damage=check));
  do damage=0 to 4;
    if damage=check then result=1;
    else result=0;
    output;
  end;
run;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Minor touching up of the code, I always forget ifn() function:

data want;
  set have (rename=(damage=check));
  do damage=0 to 4;
    result=ifn(damage=check,1,0);
    output;
  end;
run;

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
  • 2 replies
  • 1085 views
  • 0 likes
  • 2 in conversation