03-26-2014 09:37 AM
I am using the below data step to set my tprfiled variable to the prior value for it except for the first record in the data set. However, it is not recognizing the first record's 0 when processing the second record--a null is inserted instead of 0. Any ideas why this is?
if _n_ ne 1 then tprfiled=lag(tprfiled);
03-26-2014 09:48 AM
Try with just -> tprfiled=lag(tprfiled); it will give null value for first row and lag values for subsequent rows.
your code is giving the same value for tprfiled which must be 0 in your source data, and lagging null value to second row.
03-26-2014 10:00 AM
I tried doing just doing just the lag initially, but wanted to accommodate the issue with the first record. But I just tried the below, which is a variation of this and it works:
if _n_ = 1 then do;
03-26-2014 09:50 AM
Not sure about lag, tried using it myself some time back and had some weird results. So this doesn't answer your question, but does do whats requested:
create table WANT as
from HAVE A
left join HAVE B
03-26-2014 10:02 AM
The only issue with this is that I have a lot more columns that I indicated and they change regularly, so I don't really want to deal with proc sql and writing out column names.