equivalent date_part function in sas

I have a sql statement to extract date object. It runs fine in Postgres but not sas. Part query is like this:

(case when date_part('month',run_date)::integer < 10 
     THEN '0'||
          date_part('month',run_date)::varchar(1)||
          date_part('year',run_date)::varchar(4)
     else  date_part('month',run_date)::varchar(2)||date_part('year',run_date)::varchar(4)
     end) as our_date

In sas, there's no date_part function. I tried datepart function. But it's not performing the same functionality. How could I make that sql statement run in sas? Thanks.

Answers


DATEPART

data have;
 timestamp='01JAN2012:08:48'dt;
run;

proc sql;
 select datepart(timestamp) format=mmddyy10., 
 timepart(timestamp) format=time.,
 month(datepart(timestamp)),
 year(datepart(timestamp))
 into :date , :time, :month, :year
 from have;
quit;

%put DATE: &date;
%put TIME: &time;
%put MONTH: &month;
%put YEAR: &year;

I think you can just use

MONTH(run_date)

and

YEAR(run_date)

Need Your Help

Symfony2 : Recursive Validation

symfony2 recursion validation

I've got an entity with some validators (not a form).

Dynamic method call in routes spec

ruby-on-rails dynamic methods rspec

I am testing simple get requests for my routes using rspec in my Rails 3.2 application. Since all are get requests, and all just have different action names which are similar to the views' names, it

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.