Help using Base SAS procedures

SAS DATES

Accepted Solution Solved
Reply
Super Contributor
Posts: 1,041
Accepted Solution

SAS DATES

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


Accepted Solutions
Solution
‎05-29-2013 01:20 PM
Super User
Posts: 11,343

Re: SAS DATES

Posted in reply to robertrao

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


All Replies
Solution
‎05-29-2013 01:20 PM
Super User
Posts: 11,343

Re: SAS DATES

Posted in reply to robertrao

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.

Super Contributor
Posts: 1,041

Re: SAS DATES

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

Super User
Posts: 19,770

Re: SAS DATES

Posted in reply to robertrao

Because you made a mistake somewhere.

Post your full code.

Super Contributor
Posts: 1,041

Re: SAS DATES

Hi,

DATE beow is numeric

data WANT;

set have;

year=year(DATE);

run;

Respected Advisor
Posts: 3,156

Re: SAS DATES

Posted in reply to robertrao

Run this:

proc contents data=want;

run;

Then post the results.

Super User
Posts: 5,497

Re: SAS DATES

Posted in reply to robertrao

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;

Super Contributor
Posts: 1,041

Re: SAS DATES

Posted in reply to Astounding

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

Sorry for the trouble

Super Contributor
Posts: 1,041

Re: SAS DATES

Posted in reply to robertrao

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

Super User
Super User
Posts: 7,039

Re: SAS DATES

Posted in reply to robertrao

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

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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