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

I have a user who is allowed to schedule flows through the management console, but who does not have access to a libname. I have another user who has access to this libname, but cannot schedule flows in the sas management console. Is it possible to use one user to schedule and when this code runs end the session and start with the other user?

1 ACCEPTED SOLUTION

Accepted Solutions
jimbarbour
Meteorite | Level 14

@a_ramos,

 

Yes, of course.  Here (below) is the macro. 

 

You have to supply a SAS date-time value to the macro.  Your SAS job will be launched immediately, as soon as you submit it, but it won't start actual execution until the SAS date-time value you supplied.

 

I'm running on a Windows system where the default time unit is seconds, so I'm using a Unit=1 (one second).  As I recall, on Unix/Aix/Linux, the default time unit is milliseconds, so you would need to change to Unit=1000.  Run a couple of tests; make sure my memory is not off here.

%LET	Run_Date_Time	=	'01SEP2020:14:06:05'dt;

%MACRO	Job_Scheduler(Run_Date_Time, Unit=1);
	%IF	%BQUOTE(&Run_Date_Time)			^=	%STR()				%THEN
		%DO;
			%LET	Run_Date_Time		=	%SYSFUNC(INPUTN((&Run_Date_Time), DATETIME20.));
			%LET	Curr_Date_Time		=	%SYSFUNC(DATETIME());

			%IF		&Curr_Date_Time		>=		&Run_Date_Time	%THEN
				%DO;
					%PUT	WARNING-  ;
					%PUT	WARNING-  +-------------------------------------------------------+;
					%PUT	WARNING:  | Requested Date-Time is already past at launch of job. |;
					%PUT	WARNING-  | Normally the Run Date-Time should be in the future.   |;
					%PUT	WARNING-  | Is this what you intended?                            |;
					%PUT	WARNING-  | Requested Date-Time = %SYSFUNC(PUTN(&Run_Date_Time,DATETIME20.))            |;
					%PUT	WARNING-  | Current Date-Time   = %SYSFUNC(PUTN(&Curr_Date_Time,DATETIME20.))            |;
					%PUT	WARNING-  +-------------------------------------------------------+;
					%PUT	WARNING-  ;
					%IF	&SYSCC			<	4					%THEN
						%LET	SYSCC	=	4;
				%END;
			%ELSE
				%DO;
					%LET	Wait_Time	=	%SYSEVALF(&Run_Date_Time	-	&Curr_Date_Time);
					%LET	Duration	=	%SYSFUNC(PUTN(&Wait_Time, TIME13.));
					%PUT	NOTE-  ;
					%PUT	NOTE-  +-------------------------------------------------------------------------------------------------+;
					%PUT	NOTE:  | Suspending SAS process &SYSJOBID for &Duration at %SYSFUNC(STRIP(%SYSFUNC(PUTN(&Curr_Date_Time,DATETIME20.)))) until %SYSFUNC(COMPRESS(%SYSFUNC(PUTN(&Run_Date_Time,DATETIME20.)))).        |;
					%PUT	NOTE-      ...;
					%LET	Sleep_Time	=	%SYSFUNC(SLEEP(&Wait_Time, &Unit));
					%PUT	NOTE-  | SAS process &SYSJOBID re-awakening at %SYSFUNC(STRIP(%SYSFUNC(PUTN(&Curr_Date_Time,DATETIME20.)))).                                           |;
					%PUT	NOTE-  +-------------------------------------------------------------------------------------------------+;
					%PUT	NOTE-  ;
				%END;
		%END;
%MEND	Job_Scheduler;

%Job_Scheduler	(&Run_Date_Time);

Let me know if you encounter any problems.

 

Hope that helps,

 

Jim

View solution in original post

7 REPLIES 7
jimbarbour
Meteorite | Level 14

That is a good question, and I hope someone will give you a more tailored answer than I can give; I haven't used the SAS Management Console.

 

However, if the individual has access to the Windows scheduler (if you're on Windows) or can run a Cron job (Unix/Aix/Linux), that can be an alternative to the SAS Management Console.  

 

Lastly, if the Win scheduler or a cron job aren't feasible, can the individual who has access to the Libname submit a SAS job directly?  If so, I have a fairly simple macro that can place the job in "suspended animation" until a specified time.  I use it to submit jobs during the day that don't start actual execution until after midnight (when system resources are more available).

 

Jim

a_ramos
Obsidian | Level 7
It is not possible to use the windows scheduler. It's blocked. Yes, the user with access to libname can send a SAS job directly. I will research a little more about cron job. Can you give me your macro?
jimbarbour
Meteorite | Level 14

@a_ramos,

 

Yes, of course.  Here (below) is the macro. 

 

You have to supply a SAS date-time value to the macro.  Your SAS job will be launched immediately, as soon as you submit it, but it won't start actual execution until the SAS date-time value you supplied.

 

I'm running on a Windows system where the default time unit is seconds, so I'm using a Unit=1 (one second).  As I recall, on Unix/Aix/Linux, the default time unit is milliseconds, so you would need to change to Unit=1000.  Run a couple of tests; make sure my memory is not off here.

%LET	Run_Date_Time	=	'01SEP2020:14:06:05'dt;

%MACRO	Job_Scheduler(Run_Date_Time, Unit=1);
	%IF	%BQUOTE(&Run_Date_Time)			^=	%STR()				%THEN
		%DO;
			%LET	Run_Date_Time		=	%SYSFUNC(INPUTN((&Run_Date_Time), DATETIME20.));
			%LET	Curr_Date_Time		=	%SYSFUNC(DATETIME());

			%IF		&Curr_Date_Time		>=		&Run_Date_Time	%THEN
				%DO;
					%PUT	WARNING-  ;
					%PUT	WARNING-  +-------------------------------------------------------+;
					%PUT	WARNING:  | Requested Date-Time is already past at launch of job. |;
					%PUT	WARNING-  | Normally the Run Date-Time should be in the future.   |;
					%PUT	WARNING-  | Is this what you intended?                            |;
					%PUT	WARNING-  | Requested Date-Time = %SYSFUNC(PUTN(&Run_Date_Time,DATETIME20.))            |;
					%PUT	WARNING-  | Current Date-Time   = %SYSFUNC(PUTN(&Curr_Date_Time,DATETIME20.))            |;
					%PUT	WARNING-  +-------------------------------------------------------+;
					%PUT	WARNING-  ;
					%IF	&SYSCC			<	4					%THEN
						%LET	SYSCC	=	4;
				%END;
			%ELSE
				%DO;
					%LET	Wait_Time	=	%SYSEVALF(&Run_Date_Time	-	&Curr_Date_Time);
					%LET	Duration	=	%SYSFUNC(PUTN(&Wait_Time, TIME13.));
					%PUT	NOTE-  ;
					%PUT	NOTE-  +-------------------------------------------------------------------------------------------------+;
					%PUT	NOTE:  | Suspending SAS process &SYSJOBID for &Duration at %SYSFUNC(STRIP(%SYSFUNC(PUTN(&Curr_Date_Time,DATETIME20.)))) until %SYSFUNC(COMPRESS(%SYSFUNC(PUTN(&Run_Date_Time,DATETIME20.)))).        |;
					%PUT	NOTE-      ...;
					%LET	Sleep_Time	=	%SYSFUNC(SLEEP(&Wait_Time, &Unit));
					%PUT	NOTE-  | SAS process &SYSJOBID re-awakening at %SYSFUNC(STRIP(%SYSFUNC(PUTN(&Curr_Date_Time,DATETIME20.)))).                                           |;
					%PUT	NOTE-  +-------------------------------------------------------------------------------------------------+;
					%PUT	NOTE-  ;
				%END;
		%END;
%MEND	Job_Scheduler;

%Job_Scheduler	(&Run_Date_Time);

Let me know if you encounter any problems.

 

Hope that helps,

 

Jim

a_ramos
Obsidian | Level 7

Thanks Jim

jimbarbour
Meteorite | Level 14

You're welcome.  Hopefully that does what you need it to do.

 

I have something more sophisticated, something SAS based that can submit daily, weekly, or monthly jobs based on the information contained in an Excel spreadsheet.  It's quite a bit more complicated, but if you have a number of jobs to run on a regular basis, using the spreadsheet beats having to submit all your jobs for the day manually.  See also my response to @SASKiwi, below.

 

Jim

SASKiwi
PROC Star

Isn't the easiest solution to give the user with scheduling privileges the permissions to allocate the library? This is like saying we trust you enough to schedule SAS jobs but we don't trust you enough to be able to access the data the scheduled jobs require (or vice versa). It doesn't make sense at all.

jimbarbour
Meteorite | Level 14

Ah, welcome to the bureaucracy zone where efficiency and reason do not apply.  🙂

 

It's never made sense to me, companies that restrict the Windows scheduler.  The Windows scheduler only allows one to do what one already has permissions for.  The Windows scheduler doesn't permit me to do things that I couldn't otherwise do.  If my ID or permissions are revoked, any job submitted via Windows scheduler will fail.   The Windows scheduler is simply a matter of efficiency (and I suppose convenience).  But it's a "scheduler" and therefore it must be locked down because "those are the rules."

 

As a work-around, I've written the simple macro I shared above as well as a slightly more complex scheduling job that reads an Excel spreadsheet, launches a series of SAS jobs per the information contained in the spreadsheet, and then launches a new iteration of itself.  The new iteration of the scheduler sleeps until the next coming midnight, then wakes up and examines that days schedule, launching jobs as needed, including yet another iteration of itself.  The only drawback to this approach is that if the machine is rebooted for any reason, the job has to be manually re-submitted.  But inasmuch as server reboots here are relatively infrequent, I've seen it run uninterrupted for 6 to 8 weeks at a stretch, which isn't too bad for a home-grown scheduler.

 

Jim

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 7 replies
  • 829 views
  • 4 likes
  • 3 in conversation