BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Malathi13
Obsidian | Level 7

Hi,

I'm trying to delete the date from my dataset and I used this statement to delete but it is not working.

 

data new;

set have;

if date eq 2/11/17 then delete;

run;

 

It is not working, I have the same format for date in my dataset and it is a numeric var.

I need to delete 2/11/17 and 2/12/17, I tried with 2/11/17 first and is nto working.

 

Any help?

 

Thank you

M

 

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

  If your date is internally stored as a numeric variable which represents the number of days since January 1, 1960 then the code shown in the screen shot should work. The DELETE statement, does work correctly, as illustrated by this sample program with 3 rows of "fake" data.

 

delete_works.png

 

  If your program does not work then there are some possibilities to investigate, as suggested:

1) if your variable is a numeric variable which represents the number of days since Jan 1, 1960, then you need to use a date constant in the IF statement;

2) If your variable is a character string that just looks like a date, but is not a number, then you need to either convert your character string to a numeric variable (using an INPUT function); use a character comparison;

3) if your variable is really a datetime value (like 11feb2017:01:15:30) then you need to use a different function to extract only the date portion from the datetime value;

4) if your variable is a number, like 20170211 or 02112017, then you will need to use different functions to turn the "plain" number into a SAS date value.

 

  Hope this illustrates that the DELETE statement does work, when your IF statement is valid.

 

cynthia

View solution in original post

4 REPLIES 4
jklaverstijn
Rhodochrosite | Level 12

This will probably work better:

 

data new;
   set have;
   if date eq "11FEB2017"d then delete;
run;

In SAS you can specify a date constant by a date9 formatted string between quotes and a 'd' behind it. Look up the docs for date, time and datetime literals.

 

Hope this helps,

- Jan.

 

Malathi13
Obsidian | Level 7

Hi Jan,

I tried that, I don't see any errors but I see the dates still exist in the dataset.

 

M

jklaverstijn
Rhodochrosite | Level 12

Then it would help if you can show a sample of your data and the output of proc contents of the dataset you're working with. Maybe what you think to be a date is in fact not.

 

- Jan.

Cynthia_sas
SAS Super FREQ

Hi:

  If your date is internally stored as a numeric variable which represents the number of days since January 1, 1960 then the code shown in the screen shot should work. The DELETE statement, does work correctly, as illustrated by this sample program with 3 rows of "fake" data.

 

delete_works.png

 

  If your program does not work then there are some possibilities to investigate, as suggested:

1) if your variable is a numeric variable which represents the number of days since Jan 1, 1960, then you need to use a date constant in the IF statement;

2) If your variable is a character string that just looks like a date, but is not a number, then you need to either convert your character string to a numeric variable (using an INPUT function); use a character comparison;

3) if your variable is really a datetime value (like 11feb2017:01:15:30) then you need to use a different function to extract only the date portion from the datetime value;

4) if your variable is a number, like 20170211 or 02112017, then you will need to use different functions to turn the "plain" number into a SAS date value.

 

  Hope this illustrates that the DELETE statement does work, when your IF statement is valid.

 

cynthia

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 4461 views
  • 1 like
  • 3 in conversation