BookmarkSubscribeRSS Feed
jeremy4
Quartz | Level 8

Hi,

 

I am looking to override an existing dataset ("test"), which deletes observations where the variable "YEAR_MONTH" is in the month of September 2018. Would it be possible to edit my code as the "delete" part of my code is not in blue text when I input my code, so there may be an issue? 

 

Code

data test;
   set test;
   if '01Sep2018'd <= input(YEAR_MONTH,yymmn6.) <= '30Sep2018'd then delete;
run;

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16

Alternately use if not instead of delete

 

data test;
   set test;
   if not ('01Sep2018'd <= input(YEAR_MONTH,yymmn6.) <= '30Sep2018'd);
run;
Thanks,
Jag
novinosrin
Tourmaline | Level 20

Why reference the same dataset recursively. @ballardw  once taught me never do that. The sage's advice has been well taken. Please use

 

Proc sql;

delete from table

where......................

quit;

hashman
Ammonite | Level 13

@jeremy4:

First, as @novinosrin has said, there's no need to rewrite the entire file.  Second, since you year_month variable is character in YYYYMM pattern, there's no need to convert it to a SAS date value. Just create a view like either of the two below:

data vtest / view = vtest ;                                             
  set have (where = (year_month ne "201809")) ;                         
run ;                                                                   
                                                                        
proc sql ;                                                              
  create view vtest as select * from have where year_month ne "201809" ;
quit ;                                                                  

Then reference VTEST instead of TEST in your code downstream where the subset is needed.

 

Kind regards

Paul D. 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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