BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
fadel
Calcite | Level 5

Hi,

Im looking for how to create a script Shell in the SAS EG Server to launch my macro (with parameters) Once the data mart (in the server bibiotheques) is refreshed !

there is any solution ??

Thanks. to launch macro

1 ACCEPTED SOLUTION

Accepted Solutions
jakarman
Barite | Level 11

So the test is:  When DataMart.DM4_DATAMART_201504 exist (test the existence of a dataset) then you want to start your program for the April job processing?


Seems to me a daily check for that is sufficiënt.

A process being started every day on the desired time and that one does nothing when the mentioned condition is not met.

The mind switch is: do nothing even when started 

     instead of only being starting when the condition is fulfilled. 

---->-- ja karman --<-----

View solution in original post

25 REPLIES 25
fadel
Calcite | Level 5

So can the script launch macro just by click (like vbs in windows to launch excel macros)?

jakarman
Barite | Level 11

You can use SAS for almost anything to start and check on conditions. Please avoid VBS complexity for that.

In the concepts you are asking for a scheduler that starts a process when a  external file exists.
When you do not have it, it can be build using SAS. The design:

- Build a poller that doe a checks and verifie every x-time and than goes asleep. The Sleep function exists with SAS.

- Start a verifying condition that can be anything like other job have been run, A sas-dataset existing (internal or even external dbms) it is really anything you can do with SAS.

- Having all conditions met do a remote submit (mp-connect) or batch submit with xcmd access use a intitstmt termstmt for checking status etc

- Validate the status of those running jobs and you can email or do something different/other task.

The sky is the limit.

Launch a macro? I hope you are saying launching a sas-program. http://en.wikipedia.org/wiki/Macro_(computer_science) macro with sas are soure text manipulating. They are NOT procedures or keyboard/mouse recordings.

---->-- ja karman --<-----
fadel
Calcite | Level 5

Thanks Karman, but i dont know how to do that !! Can you give me more explications ?

jakarman
Barite | Level 11

Suppose having that polling in some code it will look like something

  %let fdlstart_cntr=1;

  %do %while (&fdlstart_cntr ge 1 & &sysrc=0 ) ;

   %include yourcode(fdl_sasrun) ;       /

   %let temp = %sysfunc( sleep(20,1) ) ;

   %put fdlstart polling loop sleep=&fdlsleep no &fdlstart_cntr  ;

   %include yourcode(fdl_checkrun) ;

   %put %sysfunc( sleep(40,1) ) wait some seconds.... ;

   %let fdlstart_cntr=%eval(&fdlstart_cntr +1 );

   %if ( %sysfunc(fileexist(???._STOP) ) ) %then %let fdlstart_cntr=0;   /* to stop the polling checking for a file created/existence */

   %end;

Suppose your SAS code fdl_sasrun is  having:

  seljobsubmit = 1 ;  /* a selection switcht allowing many testings */

  if ( fdl_status in (" ","W","w") ) then do;

      if ( jbwinstart > curdatetim & jbwinstart ne . ) then seljobsubmit = 0   ;   /* only after a time test */   

  end;

  if ( fdl_status in (" ","W","w") & seljobsubmit = 1 ) then do; /* validate existence tables SAS-datasets */

    do i=1 to dim(trgdsn);                                                          /* work a list array of possible datasets as libname.dataset   vivisible ot the polling process */

      IF ( trgdsn{i} ne ""  ) THEN do ;                                         /* only do the checking when being defined as string */

        if ( not exist(trgdsn{i})  ) then   seljobsubmit = 0 ;           /* if the mentioned does not exists the job may not start */

      end;

    end;

  end;

/* many ohter possible tests can be added */h

  if ( seljobsubmit = 1 ) Then do;

    if ( jbstatus in("W","w")  ) then fdl_status=" " ;   /* after having waited now allowed to submit */

  else do;

    if ( jbstatus = " " ) then  fdl_status="W"   ;        /* not allowed to run yet, set status to wait */ 

  end;

  if ( fdl_status= " " ) then do;

     submitstring=' .... '   ;  /* whatever is needed as batchjob using x-cmd */     Call execute(submitstring) ;

    /* this can also be a mpconnect approach */

  end;

Suppose your SAS code fdl_checkrun is checking your code is started (delay assumed to be max 20 seconds by the OS */

Some dataset existence being created by a you sas job.  And the logic is getting completed,

Making all it all by parameters and it will become a more generic approach. That is almost similar to generic schedulers able to set triggers on existence of some dataset.

The strange thing here a compared to generic schedulers s as the SAS polling job can see those datamarts, no matter where they are created , the can be tested on an acted on.  (exist function)
When having access to a creation data/time refresh indicator that can also be set and coded. Only needing to know what should be tested on.

---->-- ja karman --<-----
fadel
Calcite | Level 5

Thank you very much Karman, but my datamart exist permanently with same name, and it is refreshed with new data each month. So i want my process to be executed after this refreshment.

Soory.

.

fadel
Calcite | Level 5

Yeah, its refreshed by MSI.

my datamarts looks like that:

Serveur

     SASApp

          Bibiotheque

               DataMart

                     DM4_DATAMART

                     DM4_DATAMART_201403

                     DM4_DATAMART_201404

                     DM4_DATAMART_201405

                     DM4_DATAMART_201406

                     DM4_DATAMART_201407

                     ....

                     DM4_DATAMART_201503

I know that there is a new one ( 'DM4_DATAMART')  when the last one in this list is 'DM4_DATAMART_201503'. So the new one ( 'DM4_DATAMART') contains April data.

fadel
Calcite | Level 5

Sorry, Management Information System (MIS)

jakarman
Barite | Level 11

Nothing to be sorry, you did not tell anything of your datamart lay-out  technical background RDBMS or SAS datasets.

When it are SAS-datasets you have the ATTRN function retrieving the CRDATE value. SAS(R) 9.4 Functions and CALL Routines: Reference, Third Edition   Having a previous current one of that there you have another check.

When that datamarts are run maybe there can be made some agreement to create a file somewhere

When an external  DBMS the last update is sometimes available as dictionary information.

How do you recognize there is a new one?      

---->-- ja karman --<-----
jakarman
Barite | Level 11

So the test is:  When DataMart.DM4_DATAMART_201504 exist (test the existence of a dataset) then you want to start your program for the April job processing?


Seems to me a daily check for that is sufficiënt.

A process being started every day on the desired time and that one does nothing when the mentioned condition is not met.

The mind switch is: do nothing even when started 

     instead of only being starting when the condition is fulfilled. 

---->-- ja karman --<-----
fadel
Calcite | Level 5

Hi Karman, I tryed to do that:

%if (month(today) ge 2 & month(today) le 12) %then %do

%let mois2 = %eval(month(today) - 1);

%let annee2 = %eval(year(today));

%end

%else %do

%let mois2 = 1;

%let annee2 = %eval(year(today) - 1);

%end

%let done = 0;

%if (%sysfun(fileexist(DATAMART.DM4_DATAMART&annee2&mois2)) & (done = 0)) %then %do

   %kpisgenerals(mois1 = &mois2, annee1 = &annee2); /*my macro */

   done = 1;

%end

But the problem is that my loop will not stopped, it will be executed more than one time !! you see that ? how can i settle it ?

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 25 replies
  • 3860 views
  • 8 likes
  • 3 in conversation