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-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1536 views
  • 1 like
  • 4 in conversation