HI, I have a large database that needs to be manipulated. I want to convert the data that looks like this:
id | date1 | date2 | var1 | var2 |
1 | 2005 | 2008 | 5 | 3 |
2 | 2006 | 2008 | 1 | 2 |
to something that looks like this:
id | date1 | date2 | date3 | var1 | var2 |
1 | 2005 | 2008 | 2005 | 5 | 3 |
1 | 2005 | 2008 | 2006 | 5 | 3 |
1 | 2005 | 2008 | 2007 | 5 | 3 |
1 | 2005 | 2008 | 2008 | 5 | 3 |
2 | 2006 | 2008 | 2006 | 1 | 2 |
2 | 2006 | 2008 | 2007 | 1 | 2 |
2 | 2006 | 2008 | 2008 | 1 | 2 |
Basically, I want to convert each observation into id-years.
what is the best and most efficient way to do this?
Thanks!
If I understand what you are attempting;
Data want;
set have;
do date3 = date1 to date2;
output;
end;
run;
If I understand what you are attempting;
Data want;
set have;
do date3 = date1 to date2;
output;
end;
run;
Thank you! I'll try that!
data one;
input id: date1: date2: var1: var2:;
dur=date2-date1+1; date3=date1;
do x=1 to dur;
output;
date3+1;
end;
cards;
1 2005 2008 5 3
2 2006 2008 1 2
;
proc print; run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.