首页 > 解决方案 > MYSQL 根据循环日期范围运行数据

问题描述

我正在使用 MYSQL。基本上我正在尝试根据我自己定义的日期范围生成一个数据集。有人可以分享我如何在 SAS 中进行循环吗?例子:

 %macro date_loop(start,end);
 /*converts the dates to SAS dates*/
 %let start=%sysfunc(inputn(&start,anydtdte9.));
 %let end=%sysfunc(inputn(&end,anydtdte9.));
 /*determines the number of months between the two dates*/
 %let dif=%sysfunc(intck(month,&start,&end));
 %do i=0 %to &dif;
 /*advances the date i months from the start date and applys the DATE9.      format*/
   %let date=%sysfunc(putn(%sysfunc(intnx(month,&start,&i,b)),date9.));
  %put &date;
 %end;
%mend;

%date_loop(2017-01-31,2019-01-31)

我的 MySQL 代码的一部分: st_date 是自定义的。

SET @st_date = '2019-01-31'

DATE_FORMAT(@st_date,'%d/%m/%Y') as POSITION_DATE,

标签: mysqlloopsdatemacros

解决方案


推荐阅读