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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 418 views
  • 2 likes
  • 3 in conversation