- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi everybody,
I need help with coding an expansion in my records but I don't know where to start from. So I have the data in the following format:
fyear anndat revdat forecast analyst
12/31/2000 01/31/2000 01/31/2000 10 a
12/31/2000 01/20/2000 02/10/2000 5 b
12/31/2000 01/20/2000 04/18/2000 4 c
I want to have the following table where each of the records is expanded for the number of periods (months) between anndat and revdat.
fyear anndat revdat forecast analyst transaction monthyear
12/31/2000 01/31/2000 01/31/2000 10 a 1 01/2000
12/31/2000 01/20/2000 02/10/2000 5 b 2 01/2000
12/31/2000 01/20/2000 02/10/2000 5 b 2 02/2000
12/31/2000 01/20/2000 04/18/2000 4 c 3 01/2000
12/31/2000 01/20/2000 04/18/2000 4 c 3 02/2000
12/31/2000 01/20/2000 04/18/2000 4 c 3 03/2000
12/31/2000 01/20/2000 04/18/2000 4 c 3 04/2000
Any help is appreciated at this point! Thanks a lot in advance
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have;
informat fyear anndat revdat mmddyy10.;
input fyear anndat revdat forecast analyst $;
cards;
12/31/2000 01/31/2000 01/31/2000 10 a
12/31/2000 01/20/2000 02/10/2000 5 b
12/31/2000 01/20/2000 04/18/2000 4 c
;
data want;
set have;
do _n_=1 to intck('month',anndat,revdat)+1;
monthyear=intnx('month',anndat,_n_-1);
output;
end;
format fyear anndat revdat mmddyy10. monthyear mmyys7. ;
proc print;run;
Obs fyear anndat revdat forecast analyst monthyear
1 12/31/2000 01/31/2000 01/31/2000 10 a 01/2000
2 12/31/2000 01/20/2000 02/10/2000 5 b 01/2000
3 12/31/2000 01/20/2000 02/10/2000 5 b 02/2000
4 12/31/2000 01/20/2000 04/18/2000 4 c 01/2000
5 12/31/2000 01/20/2000 04/18/2000 4 c 02/2000
6 12/31/2000 01/20/2000 04/18/2000 4 c 03/2000
7 12/31/2000 01/20/2000 04/18/2000 4 c 04/2000
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have;
informat fyear anndat revdat mmddyy10.;
input fyear anndat revdat forecast analyst $;
cards;
12/31/2000 01/31/2000 01/31/2000 10 a
12/31/2000 01/20/2000 02/10/2000 5 b
12/31/2000 01/20/2000 04/18/2000 4 c
;
data want;
set have;
do _n_=1 to intck('month',anndat,revdat)+1;
monthyear=intnx('month',anndat,_n_-1);
output;
end;
format fyear anndat revdat mmddyy10. monthyear mmyys7. ;
proc print;run;
Obs fyear anndat revdat forecast analyst monthyear
1 12/31/2000 01/31/2000 01/31/2000 10 a 01/2000
2 12/31/2000 01/20/2000 02/10/2000 5 b 01/2000
3 12/31/2000 01/20/2000 02/10/2000 5 b 02/2000
4 12/31/2000 01/20/2000 04/18/2000 4 c 01/2000
5 12/31/2000 01/20/2000 04/18/2000 4 c 02/2000
6 12/31/2000 01/20/2000 04/18/2000 4 c 03/2000
7 12/31/2000 01/20/2000 04/18/2000 4 c 04/2000
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Linlin,
Thanks a lot for the code! I really appreciate your help!
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It seems transaction should be 4 for the last group :
data have;
format fyear anndat revdat mmddyy10.;
input (fyear anndat revdat) (:mmddyy10.) forecast analyst $;
datalines;
12/31/2000 01/31/2000 01/31/2000 10 a
12/31/2000 01/20/2000 02/10/2000 5 b
12/31/2000 01/20/2000 04/18/2000 4 c
;
data want(drop=i);
set have;
transaction = intck("MONTH", anndat, revdat) + 1;
format monthYear MMYYS7.;
monthyear = anndat;
do i = 1 to transaction;
output;
monthyear = intnx("MONTH",monthyear,1,"SAME");
end;
run;
proc print; run;
PG
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi PGStats,
Thank you very much for the prompt response. 'transaction' is not that important. I just put it there to show that each record is repeated for a certain number of periods. I see your point though, cos' I think you understood that transaction means the number of expanded records.
In any case the code works and I am grateful
JP