- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 06-16-2016 05:48 AM
(1702 views)
| Year | Quarter | Quarter_id |
| 2000 | 1 | 3 |
| 2000 | 2 | 6 |
| 2000 | 3 | 9 |
| 2000 | 4 | 12 |
| 2001 | 1 | 15 |
| 2001 | 2 | 18 |
| 2001 | 3 | 21 |
| 2001 | 4 | 24 |
| 2002 | 1 | 27 |
| 2002 | 2 | 30 |
| 2002 | 3 | 33 |
| 2002 | 4 | 36 |
| 2004 | 1 | 39 |
| 2004 | 2 | 42 |
| 2004 | 3 | 45 |
| 2004 | 4 | 48 |
| 2005 | 1 | 51 |
| 2005 | 2 | 54 |
| 2005 | 3 | 57 |
| 2005 | 4 | 60 |
i have year and quarter column , and i wanted to create quarter_id column , Kindly help on this in writing the code.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi subtrat1,
If your data always have all quarters, the easiest way to do it is sorting your data and then using the order on that data.
proc sort data=Have;
by year Quarter;
run;
Then you could create a sequence and multiply by 3
data want;
set have;
by year quarter;
retain count 0;
if first.quarter then count=count+1;
Quarter_ID=count*3;
drop count;
run;
If you don't have all quarters, I guess that the easiest way to do it is comparing from your origen
data want;
set have;
retain first_Year first_quarter;
if _N_=1 then do;
first_YEAR=Year;
first_quarter=quarter;
end;
Quarter_ID=(Year-first_Year)*12+Quarter*3;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Assuming your data is already in sorted order, this is probably simplest:
data want;
set have;
quarter_id + 3;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
To create a key, that can be repoduced anywhere, anytime, use a hash:
md5(cats(Year,'|',Quarter)
Data never sleeps