I am attempting to dynamically allocate a macro variable based on the availability of the macro variable name.
My problem is that for some reason when 2 or more my batch jobs run at the same time the macro variable I am using ("dog" in the example below) gets overridden by the next job. As a result I would like to read in the macro variable "dog" and change it's name to "dog1". If "dog1" is not available then check the availability of "dog2" and so on until an available name is located then specify the value (by resolving "dog").
The code I have written is as follows:
OPTIONS MPRINT MLOGIC SYMBOLGEN;
%LET DOG = SCOTT;
/*%LET DOG1 = CAT;*/
LOOPEND = 1;
DO I = 1 TO LOOPEND;
TEXT = SYMGET('DOG'||TRIM(LEFT(PUT(I,8.))));
IF TEXT = "" THEN CALL SYMPUT('DOG'||TRIM(LEFT(PUT(I,8.))),SYMGET('DOG'));
ELSE LOOPEND +1;
/*%SYMDEL DOG DOG1 DOG2 DOG3 DOG4;*/
Any help you could offer would be greatly appreciated. Thank you for your time.
That was my understanding as well, however my collegues are witnessing the override. I was hoping to create code that would prove this by dymanically creating macro variables. If there is no conflict and I can always use the 'dog1' variable then this means I am correct and the batch jobs are running in their own environment..
Basically we have a weekly.bat which kicks off 10 jobs and a daily.bat which runs 5 jobs. As each job completes it runs an include statement (which is the same for each job regardless of it's freqeuncy portalcopy.sas) kicks off a piece of code which copies the output to a sharepoint location. We use the marcro variable &decisionvar. from the first piece of code to resolve in portalcopy.sas to specify the file to be copied to sharepoint. Somehow, according to my collegues this is being overridden.
Does anyone have any suggestions as to why this is happening or a better way to prove my beliefs?
I assume that you're actually not running several independent jobs but one single job. Using %include means collecting the code from an external .sas file but then executing it in the job which is "including" the code. So if you have several %includes in one job that means all these included jobs run in the same environment - and you can overwrite things.
Better start every single job separately - or use "systask" instead of "%include" as "systask" will create a new environment per call (and you could even run the jobs in parallel).
We are running several independant jobs but also a number where it is a single job with multiple includes.
I completely agree with what you are saying.
We have a combination of the multiple includes within a job and single includes within multiple jobs. The override is perfectly acceptable for the multiple includes as they are running in sequence and therefore the job that kicks off the include needs to alter the macro variable in order for the data to be exported to the correct location. They seem to believe there are problems when running two individual jobs at the same time.
This makes absolutley no sense to me given my understanding of how macro variables work.
Here is a little macro function that will return the next available value.
%put nextdog is %nextdog;
%put nextdog is %nextdog;