zhuoer
zhuoer

Reputation: 617

What report will be produced with these SAS codes

Given the SAS data set WORK.ONE:

  X  Y   Z 
  -  -  -- 
  1  A  27 
  1  A  33 
  1  B  45 
  2  A  52 
  2  B  69 
  3  B  70 
  4  A  82 
  4  C  91

The following SAS program is submitted:

  data WORK.TWO;
     set WORK.ONE; 
     by X Y;
     if First.Y;
  run;
  proc print data=WORK.TWO noobs;
  run;

I don't understand first. and last. after a by statement with two variables. If it's like by Y; if First.Y; I know what's going on in the data step. But now, it seems a bit more complicated.

Upvotes: 0

Views: 1941

Answers (1)

Joe
Joe

Reputation: 63434

TWO will contain the records from ONE that are the first record for each new value of Y, or each new value of X (if that is any additional records). So, the first record for 1 A, 1 B, 2 A, 2 B, 3 B, 4 A, and 4 C.

Basically, in a compound BY statement, each time a variable's value changes, that variable and every variable to the right in the by statement sets first. to 1 (true).

Upvotes: 1

Related Questions