0
votes

This is the code I have written. It consists of 3 Data Steps. The first 2 work perfectly, but the last doesn't do anything and I can't work out why. Any help would be very much appreciated

data A.OCT_DEDUPE_LEVEL1;
    set A.OCT_NOMANLOGOFFERR;
    by ID_INTERNET level1 notsorted;
    if first.level1 then journey=1;
run;

As expected the above step works through my data and creates a flag, set to 1 for each first instance of level1. The next step then works through my data and groups it into 'sessions'

data A.OCT_SESSIONISE;
    SET A.OCT_DEDUPE_LEVEL1;
    IF level1 = 'Step1' and journey = 1 then session+1;
run;

This final step (below) should then work through the data again and ensure that every last thing in each session is also given a flag of journey = 1. What happens is nothing though and for the last step in each the journey field is left null.

data A.OCT_DEDUPE_SESSION;
    set A.OCT_SESSIONISE;
    if last.session then journey=1;
run;

Any ideas what is going on anyone?

Thanks in advance

1

1 Answers

3
votes

If you look at your log, it has a note:

NOTE: Variable last.session is uninitialized.

Why? Because you don't have a BY statement with session in the last data step, so you don't have a last.session variable available to you.

I'm a bit curious, why are you breaking this up, anyway? This is doable in one data step.

data A.OCT_DEDUPE_LEVEL1;
    set A.OCT_NOMANLOGOFFERR;
    by ID_INTERNET level1 notsorted;
    if first.level1 then do;
       journey=1;
       if level1='Step1' then session+1;
    end;
    if last.level1 then journey=1;
run;