BookmarkSubscribeRSS Feed
StephHe
Calcite | Level 5
Hi all,

I'm a new user of SAS so there is likely to be a very straightforward answer to my question. i have a dataset which has dates of diagnosis in the format DDMMYY. i'm trying to replace some implausible dates, so those observations that occurred at a time that was impossible, and replace them with a missing value ("."). Can anybody let me know the statements that would do this for me.

i have tried IF THEN, but it hasn't seemed to have worked...

Please help!

Thanks
5 REPLIES 5
Doc_Duke
Rhodochrosite | Level 12
First, make sure that the dates are stored internally as SAS dates. You can do this by checking the PROC CONTENTS output and looking at the data type (numeric) and display format (mmddyy.). If the contents show that the field is a character field, then you have more work to do.

IF DateDx > today() THEN datedx=.;
would change any future date to missing. You can change the expression after the IF to what you need.

If the date is actually a character string, then you first need to convert it to a date data type to do the comparison. For instance,
IF (INPUT(DateDx,mmddyy8.) > today() ) THEN DateDx=' ';
would accomplish a similar task. You may want to convert the text-date permanently to date data types.

One last thing. If your data are coming from a relational database (e.g. Oracle, SQL/Server), then the underlying field is a date-time, even though it may display as a date. You will need to either extract the date part (DATEPART is the function name) or adjust the comparisons to account for the different scaling.

Doc Muhlbaier
Duke
StephHe
Calcite | Level 5
Thanks Doc@Duke.

The underlying field was indeed date-time so I have extracted the date part. However, I am trying to replace all those observations that occurred before 01/02/1920. Though, instead it deletes those before 01/01/1960. I am aware that this is the base date, but don't know how to get round the problem.

Thanks
DavidJ
Calcite | Level 5
Are the dates being stored with two digit years or four? If they are 2 digit years, you might want to investigate the YEARCUTOFF option.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
It would be best to share exact SAS code being executed, but do so as part of a COPY/PASTE reply to your post with the SAS-generated log, not just your code piece.

Suggest you incorporate some SAS diagnostic command logic, like below, at various points in your DATA step logic flow to display data values -- also considering how you are coding any SAS DATE constants (with or without the year/century), as was mentioned previously:

PUTLOG _ALL_;

Most important, you need to share your SAS-generated log output with all code revealed to get further guidance, other than someone's guess.

Scott Barry
SBBWorks, Inc.
Peter_C
Rhodochrosite | Level 12
Rather than test very early dates as negative, use SAS Date Constant like[pre] If your_date LT "01Jan1920"d then your_date = . ; [/pre] peterC

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1142 views
  • 0 likes
  • 5 in conversation