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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.