Help using Base SAS procedures

SAS DATES

Accepted Solution Solved
Reply
Super Contributor
Posts: 1,040
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: 10,538

Re: SAS DATES

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: 10,538

Re: SAS DATES

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,040

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: 17,905

Re: SAS DATES

Because you made a mistake somewhere.

Post your full code.

Super Contributor
Posts: 1,040

Re: SAS DATES

Hi,

DATE beow is numeric

data WANT;

set have;

year=year(DATE);

run;

Respected Advisor
Posts: 3,124

Re: SAS DATES

Run this:

proc contents data=want;

run;

Then post the results.

Super User
Posts: 5,092

Re: SAS DATES

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,040

Re: SAS DATES

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,040

Re: SAS DATES

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: 6,502

Re: SAS DATES

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

☑ This topic is solved.

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

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