DATA Step, Macro, Functions and more

Problems with dates for a beginner

Reply
Occasional Contributor
Posts: 7

Problems with dates for a beginner

Hi all,

 

I have just started on SAS and have converted a text file and done multiple manipulations with it including changing dates into a relavant format.

 

I have a question, I want to recode one date point (data point 555) from 21/05/2006 to the 15/05/2006 and every method I use ends up with 1/1/1960. I have converted everything to the ddmmyy10. format.

 

For example;

data sunscreen;

modify sunscreen;

if studyid=555 then melanomadate = 15/05/2006;

 

This ends up with 1/1/1960

 

So I then tried

For example;

data sunscreen;

modify sunscreen;

if studyid=555 then melanomadate = ('15/05/2006', ddmmyy10.);

run;

 

And got error,

 

Any thoughts/ideas?

Super User
Posts: 2,516

Re: Problems with dates for a beginner

Posted in reply to underarmnat

Try

melanomadate = '15may2006'd;

Occasional Contributor
Posts: 7

Re: Problems with dates for a beginner

Thank you, works!
Super User
Posts: 2,516

Re: Problems with dates for a beginner

Posted in reply to underarmnat

15/05/2006 performs a division. The result is about 0, which is 01/01/1960 as a sas date.

Respected Advisor
Posts: 4,802

Re: Problems with dates for a beginner

Posted in reply to underarmnat

@underarmnat

Your 2nd attempt was actually pretty close. You just forgot to also use the SAS INPUT() function to tell SAS what it should be doing with the date string and the informat.

data test;
  melanomadate = input('15/05/2006', ddmmyy10.);
  format melomadate ddmmyy10.;
run;
Occasional Contributor
Posts: 7

Re: Problems with dates for a beginner

Thanks for your help Patrick
Ask a Question
Discussion stats
  • 5 replies
  • 118 views
  • 0 likes
  • 3 in conversation