2
votes

I'm completely new to SAS. My database has data from 2000-2011 and my dataset list is something like this for each date:

TP_2004012   for 26JAN2004  
TP_20040127  for 27JAN2004  
TP_20040128  for 28JAN2004

I have a numeric date like this 20100510. I want the data between 50 days and 10 days before this date (20100510). There are chances that some dates will be missing between 50 and 10 days period.

My code for this looks like:

%let yyyymmdd=20090120;

%let beg=intnx('day',date,-55);  
%let end=intnx('day',date,-10);  

data x;
set QA.TP_&yyyymmdd QA.TP_&beg-QA.TP_&end;

But this is not working.

Please help me with a suitable macro code for this.

2

2 Answers

1
votes
%let yyyymmdd=20090120;

%macro loop(yyyymmdd=, startrange=, endrange=);
%local date x ds;
%let date=%sysfunc(mdy(%substr(&yyyymmdd,5,2)
                      ,%substr(&yyyymmdd,7,2)
                      ,%substr(&yyyymmdd,1,4)));
data x;
set QA.TP_&yyyymmdd
/* loop through each specific dataset, checking first whether it exists.. */
%do x=&startrange %to &endrange;
   %let ds=QA.TP_%sysfunc(intnx(day,&date,&x),yymmddn8.);
   %if %sysfunc(exist( &ds )) %then %do;
      &ds
   %end;
%end;
;
run;
%mend; 

%loop(yyyymmdd=&yyyymmdd, startrange=-55, endrange=-10);
0
votes
%let dt=20jan2009 ;
%let beg=%SYSFUNC(intnx(day,"&DT"d,-50),8.);  
%let end=%SYSFUNC(intnx(day,"&DT"d,-10),8.);  

/* Use dictionary tables to get all the relevant datasets */
proc sql ;
  select catx('.',libname,memname) into :MEMLIST separated by ' '
  from dictionary.tables
  where libname = 'WORK'
    and memname like 'TP_%'
    and input(scan(memname,-1,'_'),yymmdd8.) between &BEG and &END 
  order by memname ;
quit ;

/* Then read all the datasets in... */
data big ;
  set &MEMLIST ;
run ;