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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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