全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
4088 4
2012-06-22
  需求是这样的:数据源在多张数据集中,表名大约是dat_yyyymm,即201111、201112、201201、201202……
我需要做一项功能,在用户设置了开始日期、结束日期,比如201111至201202,然后合并这些表中指定条件的指定字段,那么我可以:
select &retain.
from (
    select &retain. from dat_201111 where &condition.
    union all
    select &retain. from dat_201112 where &condition.
    union all
    select &retain. from dat_201201 where &condition.
    union all
    select &retain. from dat_201202 where &condition.
)
group by ...
如果用宏循环该如何做到生成连续的含有yyyymm月份的文本(且中间不能出现分号啊)呢?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2012-6-22 11:21:21
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-6-28 08:57:53
帮你写了一个生成年月列表的代码
复制代码
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-6-28 12:22:08
生成了一个宏变量 &time
就是你所要求的连续月份,且中间位空格分开的字段

data a;
do i=1900 to 2050;
do j=1 to 12;
  output;
  end;
end;
run;

data a;
set a;
if j>=10 then month=compress(i||j);
else month=compress(i||'0'||j);
run;

data b;
set a;
where month between '200901' and '201012';
run;
data b;
set b;
format time $10000.;
if _n_=1 then do; time=month; retain time; end;
else time=compress(time||'*'||month);
a='z';
run;
data b;
set b;
by a;
if last.a;
time=tranwrd(time,'*',' ');
keep time;
run;

proc sql noprint;
select time into: time
from b;
quit;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-7-15 08:04:10
复制代码

我自己写的宏方案,更具通用性。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群