DATA Step, Macro, Functions and more

script shell to launch macro in sas server

Accepted Solution Solved
Reply
Contributor
Posts: 32
Accepted Solution

script shell to launch macro in sas server

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


Accepted Solutions
Solution
‎04-17-2015 07:35 AM
Valued Guide
Posts: 3,208

Re: script shell to launch macro in sas server

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


All Replies
Super User
Posts: 6,939

Re: script shell to launch macro in sas server

I don't think that "Refresh" on a library can be used to trigger anything, if that's what you want.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 32

Re: script shell to launch macro in sas server

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

Valued Guide
Posts: 3,208

Re: script shell to launch macro in sas server

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 --<-----
Contributor
Posts: 32

Re: script shell to launch macro in sas server

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

Valued Guide
Posts: 3,208

Re: script shell to launch macro in sas server

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 --<-----
Contributor
Posts: 32

Re: script shell to launch macro in sas server

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.

.

Super User
Posts: 6,939

Re: script shell to launch macro in sas server

So your datamart is refreshed by some already existing process, right?

How is this process controlled/triggered?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 32

Re: script shell to launch macro in sas server

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.

Super User
Posts: 6,939

Re: script shell to launch macro in sas server

Could you explain what MSI is?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 32

Re: script shell to launch macro in sas server

Sorry, Management Information System (MIS)

Super User
Posts: 6,939

Re: script shell to launch macro in sas server

Then put your code into a .sas file and have that run in batch mode, triggered by the same MIS once the datamart update is finished.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Valued Guide
Posts: 3,208

Re: script shell to launch macro in sas server

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 --<-----
Solution
‎04-17-2015 07:35 AM
Valued Guide
Posts: 3,208

Re: script shell to launch macro in sas server

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 --<-----
Contributor
Posts: 32

Re: script shell to launch macro in sas server

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 ?

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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