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;
Alternately use if not instead of delete
data test;
set test;
if not ('01Sep2018'd <= input(YEAR_MONTH,yymmn6.) <= '30Sep2018'd);
run;
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;
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.
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.
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.
Ready to level-up your skills? Choose your own adventure.