BookmarkSubscribeRSS Feed
ephraim_1234
Fluorite | Level 6

So, I have a column for just years but its showing as a numeric value in sas.

 

How do I convert it to years in sas studio. 

 

What I tried

- I tried the ttransforming the data but I keep running to an error because I dont know the exact FormatTime.png

5 REPLIES 5
lhartjordan
SAS Employee
Do you want it to be a character column or a SAS date value?
ephraim_1234
Fluorite | Level 6

I want it to be a date

 

Reeza
Super User
SAS dates require a month/day component as well, so it's not a conversion, more of a calculation at that point. You can create a new variable using the MDY function and provide 1, 1 for the month/day. Then format with YEAR4 to get the same value. I am not sure what value that will add overall though.
ephraim_1234
Fluorite | Level 6

Alright, thanks.

 

can you give me like a sample code idea for it. I will work out the rest...

 

data have;
input Time;
datalines;
2011
2010
2004
;
run;

/* Create a new variable with January 1st of each year */
data want;
set have;
/*  using MDY function with January 1st */
new_date = mdy(1, 1, year); 
format new_date year4.; /* Format the date to display only the year */
run;

 

 

 

Tried this, it didnt work...

 

Reeza
Super User
You called the variable you read in time but then used the variable as YEAR in the second data step. Otherwise the approach is correct.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 5 replies
  • 794 views
  • 2 likes
  • 3 in conversation