Question

Here is the macro I'm running....

%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 Data:

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

How Can i compare fmt_Start_dt and fmt_end_dt with sysdate ? I tried something like %If fmt_start_dt<=&sysdate9 and fmt_end_dt>=sysdate9 %then %Do; in the code but values are not picking up in the loop....Any Idea??? Thanks in advance....

Was it helpful?

Solution

I'm not entirely sure what you want, but I think this might work:

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

Your FETCH function will copy dataset variables to macro variables, so you need to reference them with an ampersand. Also, you should use the TODAY() function rather than the SYSDATE9 macro variable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top