Arrangement of DATA, adding information

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 103
Accepted Solution

Arrangement of DATA, adding information

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


Accepted Solutions
Solution
‎03-10-2016 09:50 AM
Esteemed Advisor
Esteemed Advisor
Posts: 7,217

Re: Arrangement of DATA, adding information

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


All Replies
Solution
‎03-10-2016 09:50 AM
Esteemed Advisor
Esteemed Advisor
Posts: 7,217

Re: Arrangement of DATA, adding information

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;
Esteemed Advisor
Esteemed Advisor
Posts: 7,217

Re: Arrangement of DATA, adding information

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;
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 342 views
  • 0 likes
  • 2 in conversation