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:
Firm | Year | Address |
---|---|---|
x | 1990 | xxx |
x | 1991 | xxx |
x | 1994 | xxx |
x | 1996 | yyy |
and I want to convert in into:
Header 1 | Header 2 | Header 3 |
---|---|---|
x | 1990 | xxx |
x | 1991 | xxx |
x | 1992 | --- |
x | 1993 | --- |
x | 1994 | xxx |
x | 1995 | --- |
x | 1996 | yyy |
Can anyone please help me how to do that efficiently?
Thanks a lot!
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.
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.
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.
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.
Ready to level-up your skills? Choose your own adventure.