Hi everyone,
This seems like a simple problem but I can't figure it out. I want to repeat rows between two years by group.
here is a sample of my data:
data have;
input id name $ role $ year1 year2;
datalines;
1 Jon CEO 2000 2004
2 Mike President 2006 2008
3 George Advisor 2010 2010
;
And here is what I am looking for.
id | name | role | year1 | year2 | year3 |
1 | Jon | CEO | 2000 | 2004 | 2000 |
1 | Jon | CEO | 2000 | 2004 | 2001 |
1 | Jon | CEO | 2000 | 2004 | 2002 |
1 | Jon | CEO | 2000 | 2004 | 2003 |
1 | Jon | CEO | 2000 | 2004 | 2004 |
2 | Mike | President | 2006 | 2008 | 2006 |
2 | Mike | President | 2006 | 2008 | 2007 |
2 | Mike | President | 2006 | 2008 | 2008 |
3 | George | Advisor | 2010 | 2010 | 2010 |
Thank you!
Try this 🙂
data have;
input id name $ role $ year1 year2;
datalines;
1 Jon CEO 2000 2004
2 Mike President 2006 2008
3 George Advisor 2010 2010
;
data want;
set have;
do year3 = year1 to year2;
output;
end;
run;
Try this 🙂
data have;
input id name $ role $ year1 year2;
datalines;
1 Jon CEO 2000 2004
2 Mike President 2006 2008
3 George Advisor 2010 2010
;
data want;
set have;
do year3 = year1 to year2;
output;
end;
run;
Anytime
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.