DATA Step, Macro, Functions and more

Correcting dates

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

Correcting dates

 

I am having a problem correcting dates in my sas file. I already have all set sas files with dates DDMMYYYY (like 02/10/2011). Ok, but then I found that some of my dates (form some individuals) are incorrect and I want to correct it in a date step. 

Lets supose I have the individual ID = 201 with a interview date (interdate) = 02/10/2011 but I want to correct this date to 02/12/2011. 

I tried mane ways and I wasnt able to figure that out. I tried the date numbers between quota, with slash, with hifen....and so on. I also tried to format again the variable. 

Does anybody can help me...? I will have to correct several dates. I don´t want to have to export to excell every time then correct there and then import again into SAS...

 

the original enterdata is correct in the format like 02/10/2011, and it is working ok, I already caculated age of individuals from their birth date and so on. 

 

data old; se new;

if ind = 201 then enterdata  = 02122011; 

run;

 

 

 


Accepted Solutions
Solution
‎06-02-2017 09:11 AM
PROC Star
Posts: 325

Re: Correcting dates

Date literal should be in form of '02Dec2017'd

View solution in original post


All Replies
Contributor
Posts: 21

Re: Correcting dates

Hope this works

if id=201 then enterdata="02/12/2011"d
Super User
Super User
Posts: 7,942

Re: Correcting dates

Is there a logical rule to this?  You could as @gauthamk28 has shown use a date literal, however I really don't think that is what you will want to do for all ID with dates to change.  So how do you know the date should be Dec rather than Oct?  If you can provide a few lines of sample data in a datastep, and what the output should look like then we can provide example code.

Occasional Contributor
Posts: 9

Re: Correcting dates

We notice that the date was wrong because we have original patient's questionnaires and the date is actually wrong, so I need to change the date for some specific individuals because some one entered the wrong date. 

 

 

 

Super User
Super User
Posts: 7,942

Re: Correcting dates

So you have a list of the correct dates yes?  If so then why not just merge that list on and where date1 ne date2 replace date1 with date2 - this would be the more sensible option from a data management and logical route rather than manually entering some data?

Occasional Contributor
Posts: 9

Re: Correcting dates

Thanks, but it is not in a list, I have to grab the original questionnaire and fix it, and I want the correction to be written in sas-editor as a register so that other people will know the date was wrong and now correct. The answer of adding quotas and "d" worked well. 

Thanks so much for your help

Solution
‎06-02-2017 09:11 AM
PROC Star
Posts: 325

Re: Correcting dates

Date literal should be in form of '02Dec2017'd

☑ This topic is solved.

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

Discussion stats
  • 6 replies
  • 152 views
  • 2 likes
  • 4 in conversation