I am trying to create a yearly observation between 20 years that expands beyond the years.
What I have
Location Year Num
A 1980 123
A 2010 496
B 1980 1846
B 2010 1776
What I want is to create a yearly observation while retaining the Location but not the Num variable. Specifically I need to go from 1980 to 2012.
What it should look like:
Location Year Num
A 1980 123
A 1981
A ......
A 2009
A 2010 496
A 2011
A 2012
Unfortunately, it takes a few steps. But they're all short:
data years;
do year = 1980 to 2012;
output;
end;
run;
proc sql;
create table locations as select distinct location from have;
create table shell as select * from locations, years order by location, year;
quit;
data want;
merge shell have;
by location year;
run;
It's untested code, so see if it works for you.
****** Corrected ... thanks @VDD
you will need a comma in the by statement.
create table shell as select * from locations, years order by location year;
should be
create table shell as select * from locations, years order by location, year;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.