One way is to first sparse the data. You can do this by creating a template of all combinations of state and date (I hate using the variable name date for non-sas dates so I have used YRQTR here).
[pre]* Build template of data;
data allvals(keep=yrqtr state);
do state = 'CA', 'PA';
do year = 1976 to 1977 by 1;
do qtr = 1 to 4;
yrqtr = cats(put(year,4.),':',put(qtr,1.));
output allvals;
end;
end;
end;
run;[/pre]
The resulting dataset WORK.ALLVARS can now be merged or joined onto your original data. Now working with the sparsed data (like with the LAG function) will be a lot easier.
... View more