Run a code while stratifying by two variables

Viewed 21

suppose to have the following simple case (only for explanatory purposes. Original data are more complicated to show):

    data have;
    input ID :$20. Label1 :$20. Label2 :$20. Hours :$20.;
    cards;
    0001    rep1   w  345 
    0001    rep1   f  985     
    0001    rep1   w  367
    0001    rep2   w  65
    0001    rep2   w  123
    0001    rep2   f  120
    0002    rep6   f  45
    0002    rep6   w  657
    0002    rep6   w  45
    0002    rep1   w  567
    0002    rep1   f  78
    0002    rep1   w  9     
    .....   ....   ... ...
;

I would like to sum, foreach ID the hours corresponding to "w" but also stratifying by Label1, i.e. rep*. I used:

  data want;
  set have;
  by ID Label1;
      if first.ID 
      ..........
      if last.ID
      .........
  run;

Although I was able to stratify by ID I was not able to stratify by Label1. Is it possible to write as follows: if first.ID and first.Label1 then....? While doing some attempts, SAS gave me also the following error: "by variables are not properly sorted on data set have". Input data are sorted by ID.

Thank you in advance

0 Answers
Related