BookmarkSubscribeRSS Feed
mpajoh
Fluorite | Level 6
I have data set with SAS date variable spanning several years.
I want to create a variable that contains the year and the quarter (e.g 2010Q2), which can then be used to sort by.

Can anyone help?

Masoud
7 REPLIES 7
Cynthia_sas
SAS Super FREQ
Hi:
Read about the various YYQ formats. For example, a SAS date value for 03/15/2006 could be used to create a character variable called QTRVAL with this code:
[pre]
qtrval = put(date,yyq6.);
[/pre]

And the resulting value would be: 2006Q1

The documentation on the various formats is here:
http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#/documentation/cdl/...
http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#/documentation/cdl/...
http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#/documentation/cdl/...

cynthia
mpajoh
Fluorite | Level 6
Thanks Cynthia.
Peter_C
Rhodochrosite | Level 12
Masoud

what difference do you expect when sortng by (internal) sas date and sorting by quarter?

just interested
Peterc
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
With a multiple-variable BY statement, the order of observations that have date values throughout a given quarter, may get sorted differently if only considering the "formatted" value sort-sequence, presuming the BY statement has additional variables to the right of the date variable itself.

Scott Barry
SBBWorks, Inc.
mpajoh
Fluorite | Level 6
I am using the quarter variable to for proc summary's class variable.

Masoud
data_null__
Jade | Level 19
You can use the CLASS statement option GROUPINTERNAL to have you cake and eat it too.
mpajoh
Fluorite | Level 6
Thank you all.
I will have to investigate and learn.

Masoud

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
  • 7 replies
  • 1291 views
  • 0 likes
  • 5 in conversation