SAS 宏日期问题 [英] SAS Macros dates issue

查看:30
本文介绍了SAS 宏日期问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 SAS 完全陌生.我的数据库有 2000-2011 年的数据,我的数据集列表对于每个 date 都是这样的:

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

我有一个这样的数字日期 20100510.我想要这个日期之前 50 天到 10 天之间的数据(20100510).某些日期可能会在 50 到 10 天之间丢失.

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.

我的代码如下:

%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;

但这不起作用.

请帮我提供一个合适的宏代码.

Please help me with a suitable macro code for this.

推荐答案

%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);

这篇关于SAS 宏日期问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆