Desktop productivity for business analysts and programmers

How can I get the Month and Year as New variable extracted from dates on another variable?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

How can I get the Month and Year as New variable extracted from dates on another variable?

Here is the coding that I need to use:

PROC SQL;

   CREATE TABLE WORK.FILTER_FOR_XXXX AS

SELECT t1.sale_dt,

          t1.DUE_DT,

          t1.TOWN,

          t1.POSTAL_CD,

          t1.PROV_CD,

          t1.COMPETITION,

          t1.AGENT_CD,

          t1.STORE,

          t1.MRKT,

          t1.AGENT_ID,

     FROM WORK.FILTER_FOR_XXXX

      WHERE TOWN = 'NY' AND t1.sale_dt > 19724

      ORDER BY t1.sale_dt;

QUIT;


I have sale dates in variable t1.sale_dt appearing as for example 11JAN2014 (in French) etc.. I want to add to more variables one for the Month January (or 1) and the second for the Year 2014. Which exact coding should I add to have it please?


thank you.


Accepted Solutions
Solution
‎07-14-2015 03:26 PM
Frequent Contributor
Posts: 128

Re: How can I get the Month and Year as New variable extracted from dates on another variable?

This should work for you:

PROC SQL;  

CREATE TABLE WORK.FILTER_FOR_XXXX AS

SELECT t1.sale_dt,

month(t1.sale_dt) as Month format=2.,

year(t1.sale_dt) as Year format=4.,      

t1.DUE_DT,         

t1.TOWN,         

t1.POSTAL_CD,         

t1.PROV_CD,         

t1.COMPETITION,         

t1.AGENT_CD,         

t1.STORE,         

t1.MRKT,         

t1.AGENT_ID

FROM WORK.FILTER_FOR_XXXX     

WHERE TOWN = 'NY' AND t1.sale_dt > 19724     

ORDER BY t1.sale_dt;

QUIT;

View solution in original post


All Replies
Solution
‎07-14-2015 03:26 PM
Frequent Contributor
Posts: 128

Re: How can I get the Month and Year as New variable extracted from dates on another variable?

This should work for you:

PROC SQL;  

CREATE TABLE WORK.FILTER_FOR_XXXX AS

SELECT t1.sale_dt,

month(t1.sale_dt) as Month format=2.,

year(t1.sale_dt) as Year format=4.,      

t1.DUE_DT,         

t1.TOWN,         

t1.POSTAL_CD,         

t1.PROV_CD,         

t1.COMPETITION,         

t1.AGENT_CD,         

t1.STORE,         

t1.MRKT,         

t1.AGENT_ID

FROM WORK.FILTER_FOR_XXXX     

WHERE TOWN = 'NY' AND t1.sale_dt > 19724     

ORDER BY t1.sale_dt;

QUIT;

Occasional Contributor
Posts: 10

Re: How can I get the Month and Year as New variable extracted from dates on another variable?

THank you!!!

☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 311 views
  • 1 like
  • 2 in conversation