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

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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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