Question:
Suppose two companies A and B are connected in some years. Say, right now the data structure is the following:
Company 1 Company 2 Starting Year Ending Year
A B 2000 2006
A C 1998 2003
C D 1995 1997
I want to find a way to generate:
Company 1 Company 2 Year
A B 2000
A B 2001
…………….
A B 2006
A C 1998
……………..
A C 2003
C D 1995
……………..
C D 1997
Answer:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
DATA temp01; INPUT id1 id2 year1 year2; DATALINES; 100 501 1999 2003 200 688 2007 2011 333 777 1995 2008; run; data temp02; set temp01; do i= 0 to (year2-year1); year=year1+i; output; end; keep id1 id2 year; run; |
Hi Kai,
Thanks for the great codes you provide in your website. I am trying to use this code but, unfortunately, I received this error:
“ERROR: Invalid DO loop control information, either the INITIAL or TO expression is missing or
the BY expression is missing, zero, or invalid.”
Would you be able to assist?
If you paste your code, I may be able to check.
Hi Kai,
Thanks for posting your code on the website, I benefit a lot!