BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TashaBee
Fluorite | Level 6

I am trying to convert a numeric year to sas year date. The years are 2013 and 2014. When I have them converted, they are 1965 for both.

This gives me the numeric format for year: year=input(substr(compress(reporting_term,1,4),yy4.);

When I format the year using YEAR4., I am able to get the year formatted, but it gives me 1965.

Any assistance will be great.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

SAS doesn't store years as dates.  It only stores individual days.  If you have a variable that takes on values of 2013, 2014, etc., you can convert them to a legitimate day using:

year = mdy(1, 1, year);

Then the year4 format would print just the year.  You're not storing the year, you're storing January 1st of that year.  But the format controls what will print.

Good luck.

View solution in original post

3 REPLIES 3
Astounding
PROC Star

SAS doesn't store years as dates.  It only stores individual days.  If you have a variable that takes on values of 2013, 2014, etc., you can convert them to a legitimate day using:

year = mdy(1, 1, year);

Then the year4 format would print just the year.  You're not storing the year, you're storing January 1st of that year.  But the format controls what will print.

Good luck.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Erm, just store the 2013 as a number as that is all it is.  Not sure why you would want a format on that as 2013 = 2013 nothing fancy.

TashaBee
Fluorite | Level 6

Thank you!! That worked for what I needed!

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!

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.

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
  • 3 replies
  • 11832 views
  • 0 likes
  • 3 in conversation