BookmarkSubscribeRSS Feed
CharlieSong
Calcite | Level 5

Hi,

Can a order by followed by a negative date column?

 

I have a code copied from somewhere like

 

PROC SQL;
  CREATE TABLE mcapData AS
  SELECT a.permno,
  a.date,
  a.mcap
  FROM retData AS a
 

ORDER

BY a.permno,

      -a.date;
  QUIT;

 

Is that a negative sign or just some error?

7 REPLIES 7
PGStats
Opal | Level 21

It is just a trick which should be written

 

BY a,permno, a.date DESC;

 

 

PG
CharlieSong
Calcite | Level 5

Thanks! You mean I can write like that but better use DESC?

PGStats
Opal | Level 21

DESC states what you want more clearly. The next person looking at the query will not wonder what you really meant to do.

PG
CharlieSong
Calcite | Level 5

Could you tell me whether SAS allows to use like that? 

PGStats
Opal | Level 21

Yes, you can ORDER BY a SQL expression. Check the Documentation.

PG
PGStats
Opal | Level 21

Added explanation. SAS dates are just numbers. Under the hood, the date 01JAN2010 is just 18263. So -date is also just a number; -18263 when viewed as a date is 31DEC1909. When SAS is sorting by a SAS date, it is in fact just sorting numbers.

 

Hope this helps.

PG
CharlieSong
Calcite | Level 5

Hi,Thank you very much ! I understand it now.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 853 views
  • 0 likes
  • 2 in conversation