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

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