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);

格式控制数据:

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;在代码中尝试了类似的东西,但值没有在循环中拾取....有什么想法吗?提前致谢....

4

1 回答 1

1

我不完全确定你想要什么,但我认为这可能有效:

%if &fmt_start_dt <= %sysfunc(today()) and &fmt_end_dt >= %sysfunc(today()) 

您的 FETCH 函数会将数据集变量复制到宏变量,因此您需要使用 & 符号来引用它们。此外,您应该使用 TODAY() 函数而不是 SYSDATE9 宏变量。

于 2013-02-14T00:08:19.230 回答