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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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