I have a set of 100 datasets and need to remove data which was entered after 01jan2019 in all datasets which has a common variable called "masterdate". the date variable is in datetime22.3 format and with numeric type.
Can anyone help in how to do it
Hi @noda6003
You can try this:
%macro del_obs (libin, libout);
proc contents data=&libin.._all_ noprint out=dataset_list;
run;
proc sort data=dataset_list (keep=memname) nodupkey;
by memname;
run;
data _null_;
set dataset_list;
call symputx('dataset'||left(_n_), memname);
call symputx('nb_dataset',_n_);
run;
proc datasets lib=work;
delete dataset_list;
run;
%do i=1 %to &nb_dataset;
data &libout..&&dataset&i;
set &libin..&&dataset&i;
where masterdate < "01JAN2019"d;
run;
%end;
%mend del_obs;
%del_obs(library1, library2); /* Specify the libname for entry datasets, and then for output datasets*/
Pleas try the below code
1) create a libname with name folder which has all the datasets
2) create a dataset by name list which had all dataset names
3) use this list with datasets names with call execute we run the prod sort step for every dataset with the subset condition where we will keep only the records with masterdate on or before 01Jan2019.
libname folder '~path';
proc sql;
create table list as select memname from dictionary.tables where libname='FOLDER';
quit;
data _null_;
set list;
call execute('proc sort data=folder.'||strip(memname)||' out='||strip(memname)||';by var1;where datepart(masterdate)<="01jan2019"d;run;');
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.