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

Hi,

 

I have a table where I need to delete rows based on two fields, one of which is a date field in YYMMDDN8. format. The idea is to delete rows where the date is not 20170102. I tried a simple PROC SQL command to delete these rows (the date field is marked as 'y' here):

 

proc sql;

delete

from work.table

where x='12345678' and y ne 20170102;

 quit;

 

What happens is the command deletes all of the rows where x='12345678' because the date field is not in the right format. How do I need to change the code so that it works?

 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Use a date literal, or input text to a SAS date numeric.

proc sql;
  delete from work.table 
  where x='12345678' and y ne "02JAN2017"d;
quit;

Note the quotes and the d, this way only accepts ddmmmyyyy format.

The other:

proc sql;
  delete from work.table 
  where x='12345678' and y ne input('20170102',yymmdd8.);
quit;

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Use a date literal, or input text to a SAS date numeric.

proc sql;
  delete from work.table 
  where x='12345678' and y ne "02JAN2017"d;
quit;

Note the quotes and the d, this way only accepts ddmmmyyyy format.

The other:

proc sql;
  delete from work.table 
  where x='12345678' and y ne input('20170102',yymmdd8.);
quit;
tv80
Calcite | Level 5

Thank you, that worked perfectly! I had tried something similar to the first option, but with single quotation marks.

ballardw
Super User

@tv80 wrote:

Thank you, that worked perfectly! I had tried something similar to the first option, but with single quotation marks.


Single quotes should only have an impact if you are also using macro variables OR if you had spaces between any of the digits and the month name.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 5229 views
  • 0 likes
  • 3 in conversation