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

I want to delete all rows where the if statement is true for all datasets within a specific library.

 

Below is what I have done thus far, the problem with this is that it fuses all the datasets into one. I want to still keep the datasets, but just delete all rows that meet the condition

 

data temp;
	set keep2.S:;
	if f1 =. and f2 =. then delete;
run;

PS: Every dataset in the library starts with S

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

How about this? Sounds like you have an Excel file with some columns that aren't "empty".

data have;
  a = 1; b = 2; f1 = 3; f2 = 4;
  output;
   a = 1; b = 2; f1 = .; f2 = .;
  output;
run;

proc sql;
create table members as 
select libname, memname
from dictionary.members
where libname = "WORK" and memtype = "DATA"
;
quit;

data _null_;
  set members;
  where libname = 'WORK';
  call execute ('data ' !! strip(libname) !! '.' !! memname !!
                '; set ' !! strip(libname) !! '.' !! memname !!'; if f1 = . and f2 = . then delete; run;'); 
run;

View solution in original post

4 REPLIES 4
SASKiwi
PROC Star

How about this? Sounds like you have an Excel file with some columns that aren't "empty".

data have;
  a = 1; b = 2; f1 = 3; f2 = 4;
  output;
   a = 1; b = 2; f1 = .; f2 = .;
  output;
run;

proc sql;
create table members as 
select libname, memname
from dictionary.members
where libname = "WORK" and memtype = "DATA"
;
quit;

data _null_;
  set members;
  where libname = 'WORK';
  call execute ('data ' !! strip(libname) !! '.' !! memname !!
                '; set ' !! strip(libname) !! '.' !! memname !!'; if f1 = . and f2 = . then delete; run;'); 
run;
nduksy
Obsidian | Level 7

Thanks for your input. I have tried to substitute my values with your solution and I haven't gotten far. 

 

proc sql;
create table members as 
select libname, memname
from dictionary.members
where libname = "keep2" and memtype = "DATA"
;
quit;

data _null_;
  set members;
  where libname = 'keep2';
  call execute ('data ' !! strip(libname) !! '.' !! memname !!
                '; set ' !! strip(libname) !! '.' !! memname !!'; if f1 = . and f2= . then delete; run;'); 
run;

ps: The name of the library that contains the datasets is called keep2. There are 50 datasets in the library and 23 of meet that condition (f1 and f2 are blank)

 

SASKiwi
PROC Star

LIBNAMES need to be uppercase:

where libname = "KEEP2" and memtype = "DATA"

And remove the WHERE LIBNAME statement in this step:

data _null_;
  set members;
  where libname = 'keep2'; * <== remove this;
  call execute ('data ' !! strip(libname) !! '.' !! memname !!
                '; set ' !! strip(libname) !! '.' !! memname !!'; if f1 = . and f2= . then delete; run;'); 
run;

 

nduksy
Obsidian | Level 7

Thank you very much. It got the job done.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 4 replies
  • 965 views
  • 5 likes
  • 2 in conversation