BookmarkSubscribeRSS Feed
noda6003
Quartz | Level 8

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

2 REPLIES 2
ed_sas_member
Meteorite | Level 14

 

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*/
Jagadishkatam
Amethyst | Level 16

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;

Thanks,
Jag

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 426 views
  • 0 likes
  • 3 in conversation