0
這裏是宏我跑....如何比較宏中的日期值?
%macro ControlLoop(ds);
%global dset nvars nobs;
%let dset=&ds;
/* Open data set passed as the macro parameter */
%let dsid = %sysfunc(open(&dset));
/* If the data set exists, then check the number of obs ,,,then close the data set */
%if &dsid %then %do;
%If %sysfunc(attrn(&dsid,nobs))>0 %THEN %DO;;
%local dsid cols rctotal ;
%let dsid = %sysfunc(open(&DS));
%let cols=%sysfunc(attrn(&dsid, nvars));
%do %while (%sysfunc(fetch(&dsid)) = 0); /* outer loop across rows*/
/*0:Success,>0:NoSuccess,<0:RowLocked,-1:eof reach*/
%If fmt_start_dt<=&sysdate9 and fmt_end_dt>=sysdate9 %then %Do;
%do i = 1 %to &cols;
%local v t; /*To get var names and types using
varname and vartype functions in next step*/
%let v=%sysfunc(varname(&dsid,&i)); /*gets var names*/
%let t = %sysfunc(vartype(&dsid, &i)); /*gets variable type*/
%let &v = %sysfunc(getvar&t(&dsid, &i));/*To get Var values Using
GetvarC or GetvarN functions based on var data type*/
%end;
%CreateFormat(dsn=&dsn, Label=&Label, Start=&Start, fmtName=&fmtName, type=&type);
%END;
%Else %put ###*****Format Expired*****;
%END;
%END;
%else %put ###*****Data set &dset has 0 rows in it.*****;
%let rc = %sysfunc(close(&dsid));
%end;
%else %put ###*****open for data set &dset failed - %sysfunc(sysmsg()).*****;
%mend ControlLoop;
%ControlLoop(format_control);
FOrmat_Control數據:
DSN :$12. Label :$15. Start :$15. fmtName :$8. type :$3. fmt_Start_dt :mmddyy. fmt_End_dt :mmddyy.;
ssin.prd prd_nm prd_id mealnm 'n' 01/01/2013 12/31/9999
ssin.prd prd_id prd_nm mealid 'c' 01/01/2013 12/31/9999
ssin.fac fac_nm onesrc_fac_id fac1SRnm 'n' 01/01/2013 12/31/9999
ssin.fac fac_nm D3_fac_id facD3nm 'n' 01/01/2013 12/31/9999
ssin.fac onesrc_fac_id D3_fac_id facD31SR 'n' 01/01/2013 02/01/2012
oper.wrkgrp wrkgrp_nm wrkgrp_id grpnm 'n' 01/01/2013 12/31/9999
我怎麼能比較fmt_Start_dt和fmt_end_dt與SYSDATE? 我在代碼中嘗試了類似%If fmt_start_dt<=&sysdate9 and fmt_end_dt>=sysdate9 %then %Do;
的東西,但值不在循環中拾取....任何想法? 在此先感謝....
,我試過你的代碼,但這裏是問題... fmt_start_dt和fmt_end_dt都是date9格式...當我嘗試你的代碼時,我得到以下錯誤...警告:明顯的符號引用FMT_START_DT沒有解決。 錯誤:在需要數字操作數的%EVAL函數或%IF條件中找到字符操作數。條件是: &fmt_start_dt <=%sysfunc(today())和&fmt_end_dt> =%sysfunc(today()) 警告:明顯的符號引用FMT_END_DT未解決。 錯誤:宏CONTROLLOOP將停止執行。 – 2013-02-14 14:35:30
它通過將日期條件循環移動到內部循環後工作正常... – 2013-02-14 14:51:36