Help using Base SAS procedures

What does operator '+=' means in fcmp editor of Proc fcmp, it is often used in a loop to sum up summands

Reply
Contributor
Posts: 22

What does operator '+=' means in fcmp editor of Proc fcmp, it is often used in a loop to sum up summands

the same as the title

Super User
Super User
Posts: 7,050

Re: What does operator '+=' means in fcmp editor of Proc fcmp, it is often used in a loop to sum up summands

Posted in reply to ShufeGuoding

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;

Contributor
Posts: 71

Re: What does operator '+=' means in fcmp editor of Proc fcmp, it is often used in a loop to sum up summands

Posted in reply to ShufeGuoding

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;

Ask a Question
Discussion stats
  • 2 replies
  • 141 views
  • 0 likes
  • 3 in conversation