Why isn't my SAS date conversion and my month extraction not working?

Accepted Solution Solved
Reply
Contributor
Posts: 37
Accepted Solution

Why isn't my SAS date conversion and my month extraction not working?

[ Edited ]

I can't figure out why this isn't working as I have used this code before!

 

What am I doing wrong?

 

I am trying to extract month from a date variable. But before I do that I am trying to convert my date variable into a SAS date

 

Here is my code:

 

Data test
set test1 
serv_date = (input(put(Service_Date,8.),yymmdd8.)); 
                  format serv_date date9.;

	months=month(service_date);

run;

My original service_date variable is TYPE=Num and  FORMAT=BEST.


Accepted Solutions
Solution
‎12-21-2016 11:35 AM
Super User
Super User
Posts: 7,401

Re: Why isn't my SAS date conversion and my month extraction not working?

You have a load of typos which it the problem.  Missing semicolon after data line, month() taking the wrong variable.  Try this:

data test;
  service_date=160801;
  serv_date = (input(put(Service_Date,8.),yymmdd8.)); 
  format serv_date date9.;
months=month(serv_date); run;

View solution in original post


All Replies
Super User
Posts: 10,500

Re: Why isn't my SAS date conversion and my month extraction not working?

Do you get any warnings or errors in the log when you run the code?

 

But since you went to effort to create serv_date you may want

 

months=month(serv_date);

instead of

months=month(service_date);

Solution
‎12-21-2016 11:35 AM
Super User
Super User
Posts: 7,401

Re: Why isn't my SAS date conversion and my month extraction not working?

You have a load of typos which it the problem.  Missing semicolon after data line, month() taking the wrong variable.  Try this:

data test;
  service_date=160801;
  serv_date = (input(put(Service_Date,8.),yymmdd8.)); 
  format serv_date date9.;
months=month(serv_date); run;
Contributor
Posts: 37

Re: Why isn't my SAS date conversion and my month extraction not working?

Oh god! I spent way too long on this, i think I need a break!

 

Thank you!

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 177 views
  • 1 like
  • 3 in conversation