I am obviously a self taught SAS user and a newbie. Any sort of help is appreciated.
I have a variable called EVENTDATE and according to PROC CONTENTS the format for this variable is DATETIME22.3. I would like to run an analysis using only the year part --not interested about the month, day or time. Can anyone tell me the sas code so I can extract the year so I can run a basic analysis?
Thank you.
You could try: year(*)
where the * is replaced by your date variable name.
Year= year(datepart(variable));
Or depending on the proc you can simply apply a format to your variable of
format variable dtyear.;
There are various ways, using DATEPART and YEAR function or DTYEAR format, see below
Mr. Bruno Muller thank you. It worked but for some reason the only year the comes out is 2014. I can see in the LOG that my EVENTDATE are all from today.
When i looked in the SQL server database I am using, the dates ranged from 2008-2014. Any idea what might be going on?
Just in case the two lines
eventDate = datetime();
format eventDate datetime22.3;
are only for testing purposes, they are not needed in your code
Post your code
I got it to work. Thank you!
mark as answered please
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.