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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.