BookmarkSubscribeRSS Feed
vapodaca11
Calcite | Level 5

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

2 REPLIES 2
Astounding
PROC Star

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 

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

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;

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


Register now!

How to connect to databases in SAS Viya

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.

Discussion stats
  • 2 replies
  • 697 views
  • 0 likes
  • 3 in conversation