作者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)