DATA Step, Macro, Functions and more

Extract year from a date

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

Extract year from a date

Hello!

 

I would like to extract the year of a date but i can't find of to do it.

 

I use proc sql to have the max et min date but i do not know how to get only the year and store them into macro variable

proc sql;
select max(date) as maxdate, min(date) as mindate
from projet.p;
quit;

%let maxdate = ..

%let mindate= ...

 

Could you help me please?


Accepted Solutions
Solution
‎12-28-2017 05:14 PM
PROC Star
Posts: 8,115

Re: Extract year from a date

Posted in reply to prehendere
proc sql noprint;
  select year(max(date)),year(min(date))
    into :max_year, :min_year
      from projet.p
  ;
quit;

Art, CEO, AnalystFinder.com

 

View solution in original post


All Replies
PROC Star
Posts: 1,351

Re: Extract year from a date

[ Edited ]
Posted in reply to prehendere
proc sql;
select year(max(date)) into :macro_year
from projet.p; quit;

%put &macro_year;

%let year=&macro_year;

%put &year;
Solution
‎12-28-2017 05:14 PM
PROC Star
Posts: 8,115

Re: Extract year from a date

Posted in reply to prehendere
proc sql noprint;
  select year(max(date)),year(min(date))
    into :max_year, :min_year
      from projet.p
  ;
quit;

Art, CEO, AnalystFinder.com

 

Occasional Contributor
Posts: 5

Re: Extract year from a date

thank you!

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 368 views
  • 0 likes
  • 3 in conversation