I used following code to automatic split datasets within one library.
- Firstly, I use proc sql to put all dataset into a table and number them.
- Secondly, I also use proc sql to read the content in each dataset in order to set rules for split. More specifically, the split process is based on two variable: date_l_ and _ric. Obviously, date_l_ is a date variable. And _ric is a variable that identify the name of stock. The results of this step is shown as following:
- Finally, I use %do j=1 %to &obs. to split the dataset.
The following are my codes.
%macro split(sourcelib=,source=,result=);
proc sql noprint; /*read datasets in a library*/
create table mytables as
select *
from dictionary.tables
where libname = &sourcelib
order by memname ;
select count(memname)
into:numb
from mytables;
%let numb=&numb.; /*give a number to datasets in the library*/
select memname
into :memname1-:memname&numb.
from mytables;
quit;
%do i=1 %to &numb.;
proc sql noprint;
create table tmp&i as
select distinct date_l_, _ric
from &source.&&memname&i;
select count(*)
into :obs
from work.tmp&i.;
%let obs=&obs.; /*read the variable 'date_l_' and '_ric' in each dataset*/
select date_l_, _ric, catx("_", "&result.", substr(_ric, 1, 13), date_l_)
into :date_l_1-:date_l_&obs., :ric1-:ric&obs., :setname1-:setname&obs.
from work.tmp&i;
quit;
%end;
data
%do j = 1 %to &obs.; /*set rules for separated dataset*/
&&setname&j
%end;
;
set
%do i=1 %to &numb.;
&source.&&memname&i
%end;
;
select;
%do j = 1 %to &obs.;
when(_ric = "&&ric&i" and date_l_ = &&date_l_&i) output &&setname&j;
%end;
end;
%mend;
%split(sourcelib='DATA',source=DATA.,result=AXP.);
However, I faced to the error as shown following: According to Problem note: If SAS has to acquire memory in order to process a direct access bound library, and memory has already been exhausted, error messages might occur in the SASLOG.
Since I have around 100 dataset and contrain various data and RIC (variable name), it is impossible to split the dataset manually. In this case, how could I improve my code to improve this code?