BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Shayan2012
Quartz | Level 8

Hi all,

I have this data set on firm-years with their location addresses from 1990-2005. The original data set has not the address for all of the years, so there is no observation included for that specific year. However, I want to add those firm-years to the data set in an efficinet way.

So, this is my current data set:

FirmYearAddress
x1990xxx
x1991xxx
x1994xxx
x1996yyy

and I want to convert in into:

Header 1Header 2Header 3
x1990xxx
x1991xxx
x1992---
x1993---
x1994xxx
x1995---
x1996yyy

Can anyone please help me how to do that efficiently?

Thanks a lot!

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

This I believe has been asked and answered many times, so do a search you will learn more solutions, the following is just one of them.

data have;

input Firm$ Year Address$;

cards;

x 1990 xxx

x 1991 xxx

x 1994 xxx

x 1996 yyy

;

data want;

  merge have have(keep=year firm rename=(year=_y firm=_f) firstobs=2);

output;

if firm=_f then do year=year+1 to _y-1;

call missing (address);

  output;

  end;

drop _:;

run;

Haikuo

Last version was not rigorously tested, hence the update.

View solution in original post

1 REPLY 1
Haikuo
Onyx | Level 15

This I believe has been asked and answered many times, so do a search you will learn more solutions, the following is just one of them.

data have;

input Firm$ Year Address$;

cards;

x 1990 xxx

x 1991 xxx

x 1994 xxx

x 1996 yyy

;

data want;

  merge have have(keep=year firm rename=(year=_y firm=_f) firstobs=2);

output;

if firm=_f then do year=year+1 to _y-1;

call missing (address);

  output;

  end;

drop _:;

run;

Haikuo

Last version was not rigorously tested, hence the update.

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 Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 950 views
  • 1 like
  • 2 in conversation