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?
It is just a trick which should be written
BY a,permno, a.date DESC;
Thanks! You mean I can write like that but better use DESC?
DESC states what you want more clearly. The next person looking at the query will not wonder what you really meant to do.
Could you tell me whether SAS allows to use like that?
Yes, you can ORDER BY a SQL expression. Check the Documentation.
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.
Hi,Thank you very much ! I understand it now.
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.
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.