BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AmirSari
Quartz | Level 8

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.

idnameroleyear1year2year3
1JonCEO20002004 2000
1JonCEO20002004 2001
1JonCEO20002004 2002
1JonCEO20002004 2003
1JonCEO20002004 2004
2MikePresident20062008 2006
2MikePresident20062008 2007
2MikePresident20062008 2008
3GeorgeAdvisor20102010 2010

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

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;
AmirSari
Quartz | Level 8
Thank you!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 523 views
  • 1 like
  • 2 in conversation