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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.