the same as the title
I do not know of any += operator. There is a sum statement (different from the addition operator).
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000289454.htm
data new ;
set old ;
sumx + x ;
run;
Is equivalent to:
data new ;
set old ;
retain sumx ;
sumx = sum(sumx,x) ;
run;
You see this type of thing in other programming languages. Python and C# (and therefore Java) all have it. If conversation with someone, you refer to it as "op equals" as in an operator and equals.
In these languages, it is shorthand for performing a calculation of a variable on itself. Example:
myvar = 1
myvar = myvar + 1
We know the above will result in myvar being assigned a value of 2.
Instead you can write:
myvar = 1
myvar += 1
And again, myvar is now 2.
Any operator should work, not just addition.
I tested this in FCMP and it works.
proc fcmp outlib = sasuser.FCMP_addval.fcns;
function addx(y,x);
y += x;
return(y);
endsub;
quit;
options cmplib=(sasuser.FCMP_addval);
proc fcmp;
myvar = 8;
put "The value of myvar is:" myvar;
myvar = addx(myvar,10);
put "Testing Function Call";
put "Myvar is now:" myvar;
quit;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.