<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Next Available Macro Variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Next-Available-Macro-Variable/m-p/19401#M3938</link>
    <description>Thank you, that is very helpful.</description>
    <pubDate>Thu, 23 Jun 2011 05:42:13 GMT</pubDate>
    <dc:creator>Scottcom4</dc:creator>
    <dc:date>2011-06-23T05:42:13Z</dc:date>
    <item>
      <title>Next Available Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Next-Available-Macro-Variable/m-p/19394#M3931</link>
      <description>Good Morning All,&lt;BR /&gt;
&lt;BR /&gt;
I am attempting to dynamically allocate a macro variable based on the availability of the macro variable name.  &lt;BR /&gt;
&lt;BR /&gt;
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").&lt;BR /&gt;
&lt;BR /&gt;
The code I have written is as follows:&lt;BR /&gt;
&lt;BR /&gt;
OPTIONS MPRINT MLOGIC  SYMBOLGEN;&lt;BR /&gt;
&lt;BR /&gt;
%LET DOG = SCOTT;&lt;BR /&gt;
/*%LET DOG1 = CAT;*/&lt;BR /&gt;
DATA STUFF;&lt;BR /&gt;
&lt;BR /&gt;
	LOOPEND = 1;&lt;BR /&gt;
&lt;BR /&gt;
	DO I = 1 TO LOOPEND;&lt;BR /&gt;
&lt;BR /&gt;
    TEXT = SYMGET('DOG'||TRIM(LEFT(PUT(I,8.))));&lt;BR /&gt;
&lt;BR /&gt;
	IF TEXT = "" THEN CALL SYMPUT('DOG'||TRIM(LEFT(PUT(I,8.))),SYMGET('DOG'));	&lt;BR /&gt;
				 ELSE LOOPEND +1;&lt;BR /&gt;
	 		 			&lt;BR /&gt;
	END;&lt;BR /&gt;
&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
%PUT _GLOBAL_;&lt;BR /&gt;
&lt;BR /&gt;
/*%SYMDEL DOG DOG1 DOG2 DOG3 DOG4;*/&lt;BR /&gt;
&lt;BR /&gt;
Any help you could offer would be greatly appreciated.  Thank you for your time.&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Scott</description>
      <pubDate>Wed, 22 Jun 2011 22:53:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Next-Available-Macro-Variable/m-p/19394#M3931</guid>
      <dc:creator>Scottcom4</dc:creator>
      <dc:date>2011-06-22T22:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: Next Available Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Next-Available-Macro-Variable/m-p/19395#M3932</link>
      <description>Hi&lt;BR /&gt;
&lt;BR /&gt;
Every single batch job runs in its own environment so one batch job overwritting a macro variable from another batch job can't happen.&lt;BR /&gt;
&lt;BR /&gt;
To check for existence of a macro variable in a data step use "symexist()" function. There is also a dictionary table (sashelp.vmacro) which you could query.&lt;BR /&gt;
&lt;BR /&gt;
But as said: Batch jobs won't overwrite each others' environment. So may be you investigate the cause of the issue first.&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
      <pubDate>Thu, 23 Jun 2011 00:30:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Next-Available-Macro-Variable/m-p/19395#M3932</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2011-06-23T00:30:31Z</dc:date>
    </item>
    <item>
      <title>Re: Next Available Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Next-Available-Macro-Variable/m-p/19396#M3933</link>
      <description>Hi Patrick,&lt;BR /&gt;
&lt;BR /&gt;
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..&lt;BR /&gt;
&lt;BR /&gt;
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 &amp;amp;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.&lt;BR /&gt;
&lt;BR /&gt;
Does anyone have any suggestions as to why this is happening or a better way to prove my beliefs?&lt;BR /&gt;
&lt;BR /&gt;
Thank you for your help.</description>
      <pubDate>Thu, 23 Jun 2011 00:49:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Next-Available-Macro-Variable/m-p/19396#M3933</guid>
      <dc:creator>Scottcom4</dc:creator>
      <dc:date>2011-06-23T00:49:30Z</dc:date>
    </item>
    <item>
      <title>Re: Next Available Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Next-Available-Macro-Variable/m-p/19397#M3934</link>
      <description>Hi Guys,&lt;BR /&gt;
&lt;BR /&gt;
Thank you for your help, but I finally worked it out.  I just needed another approach.  The code is attached if you are interested.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
OPTIONS MPRINT MLOGIC SYMBOLGEN;&lt;BR /&gt;
&lt;BR /&gt;
%LET DOG = SCOTT;&lt;BR /&gt;
&lt;BR /&gt;
Data stuff1;&lt;BR /&gt;
I = 1;&lt;BR /&gt;
loop: TEXT = SYMGET('DOG'||TRIM(LEFT(PUT(I,8.))));&lt;BR /&gt;
if TEXT = "" then goto done;&lt;BR /&gt;
I+ +1;&lt;BR /&gt;
goto loop;&lt;BR /&gt;
done: CALL SYMPUT('DOG'||TRIM(LEFT(PUT(I,8.))),SYMGET('DOG'));&lt;BR /&gt;
Run;&lt;BR /&gt;
&lt;BR /&gt;
%put _USER_;</description>
      <pubDate>Thu, 23 Jun 2011 01:13:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Next-Available-Macro-Variable/m-p/19397#M3934</guid>
      <dc:creator>Scottcom4</dc:creator>
      <dc:date>2011-06-23T01:13:01Z</dc:date>
    </item>
    <item>
      <title>Re: Next Available Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Next-Available-Macro-Variable/m-p/19398#M3935</link>
      <description>Hi&lt;BR /&gt;
&lt;BR /&gt;
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.&lt;BR /&gt;
&lt;BR /&gt;
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).&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
      <pubDate>Thu, 23 Jun 2011 01:22:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Next-Available-Macro-Variable/m-p/19398#M3935</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2011-06-23T01:22:33Z</dc:date>
    </item>
    <item>
      <title>Re: Next Available Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Next-Available-Macro-Variable/m-p/19399#M3936</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
We are running several independant jobs but also a number where it is a single job with multiple includes.  &lt;BR /&gt;
&lt;BR /&gt;
I completely agree with what you are saying.&lt;BR /&gt;
&lt;BR /&gt;
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.&lt;BR /&gt;
&lt;BR /&gt;
This makes absolutley no sense to me given my understanding of how macro variables work.&lt;BR /&gt;
&lt;BR /&gt;
Thank you again for your help.</description>
      <pubDate>Thu, 23 Jun 2011 01:45:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Next-Available-Macro-Variable/m-p/19399#M3936</guid>
      <dc:creator>Scottcom4</dc:creator>
      <dc:date>2011-06-23T01:45:38Z</dc:date>
    </item>
    <item>
      <title>Re: Next Available Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Next-Available-Macro-Variable/m-p/19400#M3937</link>
      <description>Here is a little macro function that will return the next available value.&lt;BR /&gt;
[pre]&lt;BR /&gt;
%let dog=scott;&lt;BR /&gt;
%let dog1=bill;&lt;BR /&gt;
%let dog2=george;&lt;BR /&gt;
%let dog3=notsue;&lt;BR /&gt;
%macro nextdog;&lt;BR /&gt;
%local cnt;&lt;BR /&gt;
%let cnt=;&lt;BR /&gt;
%do %while(%symexist(dog&amp;amp;cnt)); &lt;BR /&gt;
   %let cnt=%eval(&amp;amp;cnt+1);&lt;BR /&gt;
%end;&lt;BR /&gt;
&amp;amp;cnt&lt;BR /&gt;
%mend nextdog;&lt;BR /&gt;
%put nextdog is %nextdog;&lt;BR /&gt;
%let dog%nextdog=Johnny;&lt;BR /&gt;
%put nextdog is %nextdog;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 23 Jun 2011 05:17:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Next-Available-Macro-Variable/m-p/19400#M3937</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2011-06-23T05:17:06Z</dc:date>
    </item>
    <item>
      <title>Re: Next Available Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Next-Available-Macro-Variable/m-p/19401#M3938</link>
      <description>Thank you, that is very helpful.</description>
      <pubDate>Thu, 23 Jun 2011 05:42:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Next-Available-Macro-Variable/m-p/19401#M3938</guid>
      <dc:creator>Scottcom4</dc:creator>
      <dc:date>2011-06-23T05:42:13Z</dc:date>
    </item>
  </channel>
</rss>

