Hello,
I have a problem with a macro variable that SAS changes upon compilation, when I have positioned it inside an rsubmit statement.
Specifically, if I run the following code
rsubmit;
%let longStringInSas=70044562 70038118 70000987 70006274 70006876 70009855 70010417 70010502 70010846 70013132 70013741 70017303 70017365 70018846 70018970 70019083 70019999 70020810 70023702 70024663 70027142 70027281 70027650 70029126 70032494 70035989 70037073 70044862 70050145;
endrsubmit;
then I get the following in the log (which carries over as a mistake to what I'm trying to do):
10123 rsubmit;
NOTE: Remote submit to SASHOST commencing.
13384 %let longStringInSas=70044562 70038118 70000987 70006274 70006876 70009855 70010417 70010502 70010846 70013132 70013741 70017303 70017365 70018846 70018970 70019083 70019999 70020810 70023702 70024663 70027142 70027281
13384! 70027650 70029126 70032494 70035989
13385 7003707370044862 70050145;
NOTE: Remote submit to SASHOST complete.
Notice how the second to last and third to last numbers are concatenated.
If I submit the %let statement without including the rsubmit-statements, then the log seems fine:
10124 %let longStringInSas=70044562 70038118 70000987 70006274 70006876 70009855 70010417 70010502 70010846 70013132 70013741 70017303 70017365 70018846 70018970 70019083 70019999 70020810 70023702 70024663 70027142 70027281
10124! 70027650 70029126 70032494 70035989 70037073 70044862 70050145;
How come does this work differently depending on whether I use rsubmit or not? And any ideas as to how to make it work within rsubmit?
Kind regards,
Hedegaard.
It worked for me both inside and outside of an rsubmit block with your string (Win7 64bit, SAS 9.2 TS Level 2M3). What SAS version and OS are you using (for both the "local" and remote session?).
What you see is a log message. Are you also having missing blanks if you %put the macro variable to the log?
You can always create the macro variable locally and then push it to the remote session using %syslput.
Or you could pass the string in several steps, something like
%let longStringInSas=70044562 70038118 70000987 70006274 70006876 70009855;
%let longStringInSas=&longStringInSas 70010417 70010502 70010846 70013132 70013741;
%let longStringInSas=&longStringInSas 70017303 70017365 70018846 70018970 70019083;
%let longStringInSas=&longStringInSas 70019999 70020810 70023702 70024663 70027142;
%let longStringInSas=&longStringInSas 70027281 70027650 70029126 70032494 70035989;
%let longStringInSas=&longStringInSas 70037073 70044862 70050145;
The only thing I can think of creating the problem is some CR/LF issue where you have a mix of a Windows and a UNIX/Linux environment.
It worked for me both inside and outside of an rsubmit block with your string (Win7 64bit, SAS 9.2 TS Level 2M3). What SAS version and OS are you using (for both the "local" and remote session?).
What you see is a log message. Are you also having missing blanks if you %put the macro variable to the log?
You can always create the macro variable locally and then push it to the remote session using %syslput.
Or you could pass the string in several steps, something like
%let longStringInSas=70044562 70038118 70000987 70006274 70006876 70009855;
%let longStringInSas=&longStringInSas 70010417 70010502 70010846 70013132 70013741;
%let longStringInSas=&longStringInSas 70017303 70017365 70018846 70018970 70019083;
%let longStringInSas=&longStringInSas 70019999 70020810 70023702 70024663 70027142;
%let longStringInSas=&longStringInSas 70027281 70027650 70029126 70032494 70035989;
%let longStringInSas=&longStringInSas 70037073 70044862 70050145;
The only thing I can think of creating the problem is some CR/LF issue where you have a mix of a Windows and a UNIX/Linux environment.
Hello, Patrick.
Thanks.
The local SAS version is 9.1 and local OS is Win XP.
The version of SAS on the server is 9.2 - I have been told it's a Windows server.
If I %put the macro variable to the log, it still appears in the wrong way (with two of the numbers being concatenated). At first, I had used your suggestion of defining the string in several steps, which worked, but was unpretty.
Creating the macro variable locally and pushing it to the server with %syslput seems to work much better. Using that method, I have no visible problems.
I have a peculiar problem now. When I run my program (which is way too big and involved for me to post here), it outputs among other things all but the third to last number in the macro variable. I have tried permuting the order of the numbers, and it is consistently the third to last number, which is being ignored.
I suspect that this has something to do with the variable being too long. It does this regardless of whether I use the %syslput method or the method of passing the string in several steps. Evidence for it to have something to do with the length of the string is that if I let the string contain only six numbers, then all six numbers are contained in the output.
If it is doing something odd based on position I would look for any loop or position counters getting accidentally incremented, especially if it isn't affecting the last two values.
Just out of curiousity: If you %bqoute() the string passed to the macro var does the issue remain.
A macro var should be able to store 32K. %length(¯ovar) will tell you how long the stored string currently is.
Suggest that you post this issue in a new thread so people look at it again (as this thread here is already flagged as answered). Possibly also contact SAS TechSupport.
Patrick,
32K is the default value for MVARSIZE, a option that controls the maximum size (in kilobytes) for storing a macro variable. This is not however a limitation to the length of the data stored inside a macro variable, which is 65534 as of at least 9.1
Tom makes a very valid proposition. Often rsubmit inside of macro exhibit unexpected behavior due to the nature of how sas compiles.
Syslput and sysrput are the recommended methods for transfering macro variable between sessions initiated by rsubmits.
Are you doing this inside a macro?
I know that there are problems with macro generated rsubmit code where SAS appears to be tokenizing the strings wrong.
I have had it bite me where it caused trouble and just changing the number of characters inside a comment made the code work.
Hi, all.
Thanks for the answers.
Patrick: I tried using the %bquote function, but the same problem remains. In fact, now it ignores the second to last number in the list as opposed to the third to last, like it did before. This appears to have something to do with which number is in position 256 of the string. So in
%let longStringInSas=%bquote(70044562 70038118 70000987 70006274 70006876 70009855 70010417 70010502 70010846 70013132 70013741 70017303 70017365 70018846 70018970 70019083 70019999 70020810 70023702 70024663 70027142 70027281 70027650 70029126 70032494 70035989 70037073 70044862 70050145);
the second to last number now contains the 256th position in the string, while it was the third to last one before.
Tom and FriedEgg: I am not doing this inside a macro function. The structure of the program around this assignment is:
%aMacroFunction;
%let longStringInSas=%bquote(70044562 70038118 70000987 70006274 70006876 70009855 70010417 70010502 70010846 70013132 70013741 70017303 70017365 70018846 70018970 70019083 70019999 70020810 70023702 70024663 70027142 70027281 70027650 70029126 70032494 70035989 70037073 70044862 70050145);
%syslput longStringInSas = &longStringInSas;
rsubmit;
%anotherMacroFunction;
[lots of macro variable assignments]
endrsubmit;
You should probably try to create the simpliest version of your program that exhibits the issue and send it SAS technical support.
Another way to move information between SAS/Connect sessions is with datasets instead of macro variables.
data longstr;
longstr="&longstr";
run;
rsubmit;
proc upload data=longstr out=longstr status=n; run;
data _null_;
set longstr;
call symputx('longstr',longstr);
run;
Give the following a try in your enviornment as a test.
1. Create a macro to use inside local and remote sessions (plcnt)
2. Create a macro variable (longstring) of space delimited numerics with length 9
3. Validate execution of macro in rsubmit and preservation of data in longstring
filename acm temp;
%let acm=%sysfunc(pathname(acm));
data _null_;
input;
file acm;
put _infile_;
cards4;
%macro plcnt(str);
%put Length= %length(&str) Words=%sysfunc(countw(&str));
%mend;
;;;;
run;
%include "&acm";
%let longstring=%sysfunc(repeat(%str(12345678),%sysfunc(floor(32767/9))));
%plcnt(&longstring)
signon subtask1 sascmd="/usr/local/SAS/SASFoundation/9.2/sas" wait=no;
%syslput longstring2=&longstring /remote=subtask1;
%syslput acm="&acm" /remote=subtask1;
rsubmit subtask1;
%include &acm;
%plcnt(&longstring2)
data _null_;
array x[%sysfunc(countw(&longstring2))](&longstring2);
dim=dim(x);
mean=mean(of x
put 'Keys: ' dim 'Mean: 'mean;
run;
endrsubmit subtask1;
signon subtask2 sascmd="/usr/local/SAS/SASFoundation/9.2/sas" wait=no;
%syslput longstring3=&longstring /remote=subtask2;
%syslput acm="&acm" /remote=subtask2;
rsubmit subtask2;
%include &acm;
%plcnt(&longstring3)
data _null_;
array x[%sysfunc(countw(&longstring3))](&longstring3);
dim=dim(x);
median=median(of x
put 'Keys: ' dim 'Median: 'median;
run;
endrsubmit subtask2;
waitfor _all_ subtask1 subtask2;
%plcnt(&longstring)
data _null_;
array x[%sysfunc(countw(&longstring))] (&longstring);
dim=dim(x);
mean=mean(of x
median=median(of x
put 'Keys: ' dim ' Mean: 'mean ' Median: ' median;
run;
signoff subtask1;
signoff subtask2;
Log Output for local session:
Length= 32768 Words= 3641
Length= 32768 Words= 3641
Keys: 3641 Mean: 12345678 Median: 12345678
Log Output for subtask1:
Length= 32768 Words= 3641
Keys: 3641 Mean: 12345678
Log Output for subtask2:
Length= 32768 Words= 3641
Keys: 3641 Median: 12345678
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.