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

Hi ,

How can i extracct the year from

1)date10.  (2012-11-20)

Using substring or is there any other logic??

I want 2012

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

if the value is an actual SAS date with format date10. , or actually any format,

then

year = year(datevariablename);

There are functions to pull month, day of month, day of week, quarter as well from the date values.

View solution in original post

9 REPLIES 9
ballardw
Super User

if the value is an actual SAS date with format date10. , or actually any format,

then

year = year(datevariablename);

There are functions to pull month, day of month, day of week, quarter as well from the date values.

robertrao
Quartz | Level 8

Hi,

Thanks so much for the information

I have the datevariablename as numeric

when i do

year=year( datevariablename) i get year variable as charecter.How is that happening? i was expecting year variable to be numeric too since the parent was numeric

Thanks

Reeza
Super User

Because you made a mistake somewhere.

Post your full code.

robertrao
Quartz | Level 8

Hi,

DATE beow is numeric

data WANT;

set have;

year=year(DATE);

run;

Haikuo
Onyx | Level 15

Run this:

proc contents data=want;

run;

Then post the results.

Astounding
PROC Star

Most likely, YEAR is already in your data set before you started.  So you can't change it to numeric.  But you could drop it:

data want;

   set have (drop=year);

   year = year(date);

run;

robertrao
Quartz | Level 8

Thanks for the help. I got it. I have used put function and forgot to rerun the code

Sorry for the trouble

robertrao
Quartz | Level 8

Now I have the year variable under which there are 2011,2010, 2012 and so on.

how can i use the proc report to get only the particular years report????

without subsetting in the original dataset

Regards

Tom
Super User Tom
Super User

Look of the WHERE statement.  It is not limited to PROC REPORT.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 2295 views
  • 6 likes
  • 6 in conversation