## DATA Step, Macro, Functions and more

Solved
Occasional Contributor
Posts: 16

Hello everyone,

I have this table

 DATE COUNT CO DE GRADE SUM 201401 4472 0 0 1 4476 201401 8691 0 0 2 8713 201401 8289 0 0 3 8370 201401 4 0 1 1 . 201401 22 0 1 2 . 201401 81 0 1 3 . 201401 11642 1 0 1 11651 201401 19361 1 0 2 19420 201401 15284 1 0 3 15425 201401 9 1 1 1 . 201401 59 1 1 2 . 201401 141 1 1 3 .

I want this

 DATE COUNT CO DE GRADE SUM SUM2 201401 4472 0 0 1 4476 . 201401 8691 0 0 2 8713 . 201401 8289 0 0 3 8370 . 201401 4 0 1 1 . 4476 201401 22 0 1 2 . 8713 201401 81 0 1 3 . 8370 201401 11642 1 0 1 11651 . 201401 19361 1 0 2 19420 . 201401 15284 1 0 3 15425 . 201401 9 1 1 1 . 11651 201401 59 1 1 2 . 19420 201401 141 1 1 3 . 15425

Basecally I want make another column SUM2 same as SUM but start in row 4.

Is there anybody who can solve my problem?

Accepted Solutions
Solution
‎08-02-2017 07:00 AM
PROC Star
Posts: 1,265

like this?

``````data have;
input DATE:yymmn6. COUNT CO DE GRADE SUM ;
format DATE yymmn6.;
datalines;
201401 4472 0 0 1 4476
201401 8691 0 0 2 8713
201401 8289 0 0 3 8370
201401 4 0 1 1 .
201401 22 0 1 2 .
201401 81 0 1 3 .
201401 11642 1 0 1 11651
201401 19361 1 0 2 19420
201401 15284 1 0 3 15425
201401 9 1 1 1 .
201401 59 1 1 2 .
201401 141 1 1 3 .
;

data want;
set have;
SUM2 = lag3(SUM);
run;``````

All Replies
Solution
‎08-02-2017 07:00 AM
PROC Star
Posts: 1,265

like this?

``````data have;
input DATE:yymmn6. COUNT CO DE GRADE SUM ;
format DATE yymmn6.;
datalines;
201401 4472 0 0 1 4476
201401 8691 0 0 2 8713
201401 8289 0 0 3 8370
201401 4 0 1 1 .
201401 22 0 1 2 .
201401 81 0 1 3 .
201401 11642 1 0 1 11651
201401 19361 1 0 2 19420
201401 15284 1 0 3 15425
201401 9 1 1 1 .
201401 59 1 1 2 .
201401 141 1 1 3 .
;

data want;
set have;
SUM2 = lag3(SUM);
run;``````
☑ This topic is solved.