BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
France
Quartz | Level 8

dear all,

 

I would like to create a quarter variable based on a date variable.

 

The FORMAT of the date is YYMMDDD10. (e.g.,1990-09-29). I use the code like 

DATA Step1.Appln_newQuarter;
   SET Step1.appln_new;
   IF MONTH(earliest_filing_date)=1 or 2 or 3 THEN quarter=1;
   ELSE IF MONTH(earliest_filing_date)=4 or 5 or 6 THEN quarter=2;
   ELSE IF MONTH(earliest_filing_date)=7 or 8 or 9 THEN quarter=3;
   ELSE IF MONTH(earliest_filing_date)=10 or 11 or 12 THEN quarter=4;   
RUN;

but the result is '1'. could you please give me some suggestions?

 

thanks in advance. 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
DATA Step1.Appln_newQuarter;
   SET Step1.appln_new;
    quarter=qtr(earliest_filing_date);
     
RUN;

Use the qtr function  -- is all you need i think 

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20
DATA Step1.Appln_newQuarter;
   SET Step1.appln_new;
    quarter=qtr(earliest_filing_date);
     
RUN;

Use the qtr function  -- is all you need i think 

ballardw
Super User

@France wrote:

dear all,

 

I would like to create a quarter variable based on a date variable.

 

The FORMAT of the date is YYMMDDD10. (e.g.,1990-09-29). I use the code like 

DATA Step1.Appln_newQuarter;
   SET Step1.appln_new;
   IF MONTH(earliest_filing_date)=1 or 2 or 3 THEN quarter=1;
   ELSE IF MONTH(earliest_filing_date)=4 or 5 or 6 THEN quarter=2;
   ELSE IF MONTH(earliest_filing_date)=7 or 8 or 9 THEN quarter=3;
   ELSE IF MONTH(earliest_filing_date)=10 or 11 or 12 THEN quarter=4;   
RUN;

but the result is '1'. could you please give me some suggestions?

 

thanks in advance. 

 

 


For a very large number of purposes you may not even need to create an additional variable at all. SAS provides several formats for date values that will display quarters: QTRw. by default displays 1 to 4, QTRRw. which displays quarter as Roman numerals: I II III and IV, YYQw which will show year and quarter information together depending on width YYQ. default shows YYYYQn such as 2018Q1 or YYQxw. where you choose a charcter for x that controls the separator between the year and quarter numbe allowing such things as 2012/3 or 2017-2.

 

Analysis procedures will honor the formatted value for grouping purposes.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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