作者da1985 ()
站内Statistics
标题[程式] SAS 一小段 macro
时间Fri Mar 4 23:13:43 2011
[软体程式类别]:SAS
[程式问题]: macro 资料处理
[软体熟悉度]: 低(1~3个月)
[问题叙述]:
下面这段macro是在挑日期出来
有几个问题请教
1. 在macroc中,不是都得使用"%"吗? (ex: %if %then %do etc.)
为什麽在if then do 底下那段都没有用到%
而 else do 底下那段要就得用%
2. if then do 底下的cats(&mm.,"01")
与 else do 底下的 &mm.01
这两个写法的结果是一样的,
差别在cats有去头尾空白的功能外,还有别的差异吗?
3. 什麽时候要用%sysfunc来连接sas内建函数呢?
我知道input、put等不能包在%sysfunc底下
可是为什麽我把else do底下的putn改成put、inputn改成input
并去掉%sysfunc後就不能执行
4. yymmddn8. 与 yymmdd10. 加个n差别在?
我知道都是一些小问题,程式也有点杂
麻烦高手们见谅了^^
谢谢噜
[程式范例]:
%macro mmIntnx(mm, intnx, unit, alignment);
%if %substr(&mm.,1,1)>9 %then %do;
substr(
put(
intnx("&unit.",
input(cats(&mm., "01"),
yymmdd10.,
&intnx.,
"&alignment.”
),
yymmddn8.
)
,1,6)
%end;
%else %do;
%substr(
%sysfunc(putn(
%sysfunc(intnx(&unit.
,%fsyfunc(inputn(&mm.01,yymmdd10.))
,&intnx.
,&alignment.
)),
yymmddn8.))
,1,6)
%end;
%mend;
EX : %let x=201102;
y= %mmIntnx(&x., intnx=0, unit=month, alignment=end);
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.198.167.14
※ 编辑: da1985 来自: 114.198.167.14 (03/04 23:21)