BookmarkSubscribeRSS Feed
2 REPLIES 2
Tom
Super User Tom
Super User

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;

jaredp
Quartz | Level 8

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-2024.png

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.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 617 views
  • 0 likes
  • 3 in conversation