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.

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
  • 9 replies
  • 1203 views
  • 6 likes
  • 6 in conversation