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

I want to add another row based on the value.

In the data below, for the first observation, for example, for firm 1, starting from 15-JAN-2012, for every 12 month, for 3 times, I need to give $1000. For observation 4, for firm 2, starting from 05-FEB-2015, every 6 month, for two times, I need to give firm $1000. (I just put two firms for brevity)

Capture1.PNG

 


data schedule;
input firmid startdate mmddyy10. unit times amount;
datalines;
1 01/15/2012 12 3 1000
1 03/15/2013 12 1 2000
1 01/30/2011 3 4 500
2 02/05/2015 6 2 1000
;
run;

proc print data=schedule;
format startdate date11.;
run;

In the end, I need a table that looks like below 

Capture2.PNG

Could you please help me creating this table?

Thanks!

 

1 ACCEPTED SOLUTION

Accepted Solutions
LaurieF
Barite | Level 11

Here you go:

data schedule;
 input firmid startdate mmddyy10. unit times amount;
 attrib startdate length=4 format=date9.;
 datalines;
1 01/15/2012 12 3 1000
1 03/15/2013 12 1 2000
1 01/30/2011 3 4 500
2 02/05/2015 6 2 1000
;
run;

data want;
set schedule;
output;
do i = 1 to times - 1;
   startdate = intnx('month', startdate, unit, 's');
   output;
   end;
keep firmid startdate amount;
run;

View solution in original post

2 REPLIES 2
LaurieF
Barite | Level 11

Here you go:

data schedule;
 input firmid startdate mmddyy10. unit times amount;
 attrib startdate length=4 format=date9.;
 datalines;
1 01/15/2012 12 3 1000
1 03/15/2013 12 1 2000
1 01/30/2011 3 4 500
2 02/05/2015 6 2 1000
;
run;

data want;
set schedule;
output;
do i = 1 to times - 1;
   startdate = intnx('month', startdate, unit, 's');
   output;
   end;
keep firmid startdate amount;
run;
Sangho
Obsidian | Level 7
It works great! Thank you so much.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 2409 views
  • 4 likes
  • 2 in conversation