BookmarkSubscribeRSS Feed
ArpitSharma
Fluorite | Level 6

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

4 REPLIES 4
ballardw
Super User

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?

ArpitSharma
Fluorite | Level 6

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.

Tom
Super User Tom
Super User

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  (*;) comment.

Tom
Super User Tom
Super User

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?

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1088 views
  • 0 likes
  • 3 in conversation