Help using Base SAS procedures

SAS macro does not "update" the log

Reply
Contributor
Posts: 38

SAS macro does not "update" the log

I wrote this below code.

Brief explanation of the code:

One of my process runs  and checks for the file.

     If the file exists then its okay. Nothing to  be done in that case.

     If the file does NOT exist then it invokes another macro ---- %execute_previous_hr


The code runs correct. even the macro "execute_previous_hr" runs correct. No issues in any logic or anything like that.

BUT,

Lets say If we are missing one file- then we want to execute the macro-execute_previous_hr. It is getting executed. The log does get updated.

If we are missing more than One file- then we want to execute the macro-execute_previous_hr. It is getting executed. Only for the first run the log would get updated.

BUT the log does not get updated after that(subsequent checks/ runs).


I have "options symbolgen mprint mlogic merror;" within the macro execute_previous_hr when i am compiling it.


What am I missing here?

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

%LET _TD=%eval(%sysfunc(today())-0);

%LET _HR=10;

data _null_ ;

    call symput('scoring_date_1',put(&_TD.-1, yymmddn8.));

    call symput('_TD_1',(&_TD.-1));

run;

%put scoring_date_1---&scoring_date_1.;

%put _TD_1---&_TD_1.;

%macro chk_file_p(date,_ttdd);

options symbolgen mprint mlogic merror;

%do i = &date. %to &date.  ;

%*%LET i = &date. ;

    %do j = 0 %to 22 %BY 2;

        %if &j. < 10 %then %do;

            %if %sysfunc(fileexist(/path/of/the/file/Name_of_the_file_&i._0&j..csv)) %then %do;

            %put "FILE - YES";

            %END;

            %ELSE %DO;

            %PUT "FILE - NO. Will have to run for Hour-&j. AND DATE-&scoring_date_0.";

                %PUT CURRENT _ttdd= &_ttdd.;

                %put _HR---&j.;

                data _null_ ;

                    scoring_date=put(&_ttdd., yymmddn8.);

                    scoring_yesterday=put(&_ttdd.-1, yymmddn8.);

                    hour=&j.;

                    sdtm=dhms(&_ttdd.,hour-2,0,1);

                    edtm=dhms(&_ttdd.,hour,0,0);

                    call symput ('_filedt',catx('_',scoring_date,put(hour,z2.)));

                    call symput ('_sdttm',catq('1a',trim(left(put(sdtm,ymdt.)))));

                    call symput ('_edttm',catq('1a',trim(left(put(edtm,ymdt.)))));

                RUN;

               

                %PUT _filedt=&_filedt.;

                %PUT _sdttm=&_sdttm.;

                %PUT _edttm=&_edttm.;

               

                %execute_previous_hr;

            %END;

        %end;

        %else %do;

            %if %sysfunc(fileexist(/path/of/the/file/Name_of_the_file_&i._&j..csv)) %then %do;

            %put "FILE - YES";

            %END;

            %ELSE %DO;

            %PUT "FILE - NO. Will have to run for Hour-&j. AND DATE-&scoring_date_0.";

                %PUT CURRENT _ttdd= &_ttdd.;

                %put _HR---&j.;

                data _null_ ;

                    scoring_date=put(&_ttdd., yymmddn8.);

                    scoring_yesterday=put(&_ttdd.-1, yymmddn8.);

                    hour=&j.;

                    sdtm=dhms(&_ttdd.,hour-2,0,1);

                    edtm=dhms(&_ttdd.,hour,0,0);

                    call symput ('_filedt',catx('_',scoring_date,put(hour,z2.)));

                    call symput ('_sdttm',catq('1a',trim(left(put(sdtm,ymdt.)))));

                    call symput ('_edttm',catq('1a',trim(left(put(edtm,ymdt.)))));

                RUN;

               

                %PUT _filedt=&_filedt.;

                %PUT _sdttm=&_sdttm.;

                %PUT _edttm=&_edttm.;

                %execute_previous_hr;

%END;

        %end;

    %end;

%end;

%mend chk_file_p;

%CHK_FILE_p(&scoring_date_1.,&_TD_1.);

Super User
Posts: 11,343

Re: SAS macro does not "update" the log

Posted in reply to ArpitSharma

Since, if I understand your question correctly, the issue is when the macro %execute_previous_hr should run 2 or more times then something doesn't get put to the log. If that is the case I would really suspect it is that macro.

Have you run this code with options symbolgen, mlogic and mprint?

Contributor
Posts: 38

Re: SAS macro does not "update" the log

Yes,

I have "options symbolgen mprint mlogic merror;" within the macro execute_previous_hr when i am compiling it.

The macro will get executed for 2 or more times correctly.

It just would not put that in log.

Super User
Super User
Posts: 7,076

Re: SAS macro does not "update" the log

Posted in reply to ArpitSharma

Are you sure you do not have some unbalanced quotes or similar issues?

For example I do not like the looks of this line:

%*%LET i = &date. ;

It is dangerously close to

*%LET i = &date. ;

Which looks like a comment, but that the macro processor will treat as a %LET statement and an unclosed statement style  (*Smiley Wink comment.

Super User
Super User
Posts: 7,076

Re: SAS macro does not "update" the log

Posted in reply to ArpitSharma

Another thing to check is accidental macro variable collision. I notice that the macro you posted does not define is control variables as LOCAL. Perhaps the subroutine macro also does not define its local macro variables and it is changing I or J or one of the other macro variables that the outer loops are using?

Ask a Question
Discussion stats
  • 4 replies
  • 231 views
  • 0 likes
  • 3 in conversation