BookmarkSubscribeRSS Feed
subrat1
Fluorite | Level 6
YearQuarterQuarter_id
200013
200026
200039
2000412
2001115
2001218
2001321
2001424
2002127
2002230
2002333
2002436
2004139
2004242
2004345
2004448
2005151
2005254
2005357
2005460

 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
arodriguez
Lapis Lazuli | Level 10

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;

 

Astounding
PROC Star

Assuming your data is already in sorted order, this is probably simplest:

 

data want;

set have;

quarter_id + 3;

run;

LinusH
Tourmaline | Level 20

To create a key, that can be repoduced anywhere, anytime, use a hash:

md5(cats(Year,'|',Quarter)
Data never sleeps

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1502 views
  • 2 likes
  • 4 in conversation