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
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;
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;
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;
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!
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.
Ready to level-up your skills? Choose your own adventure.