DATA Step, Macro, Functions and more

sum

Reply
N/A
Posts: 0

sum

what is the significant of the 'OF'in x=sum(OF a1-a4,a6,a9);
Respected Advisor
Posts: 3,799

Re: sum

Posted in reply to deleted_user
It is the "signal" for the following is a "SAS Variable List". Without it the argument is A1 minus A4.

Look a documentation for "SAS Variable Lists". Message was edited by: data _null_;
N/A
Posts: 0

Re: sum

Posted in reply to data_null__
I go through the sas document but i could not able to get it.
so please explain me.

thanks in advance.
N/A
Posts: 0

Re: sum

Posted in reply to data_null__
can you explain me what is a "signal"?
Super Contributor
Super Contributor
Posts: 3,174

Re: sum

Posted in reply to deleted_user
In this context, the use of "signal" simply means this technique is using a SAS programming/code argument "OF" and when coded as shown it is treated differently than a more typical SUM(...) function execution.

Scott Barry
SBBWorks, Inc.

Google advanced search argument, this topic/post:

sum function site:sas.com

-> generated several results, including the link below were "OF" is explained in the SUM function documentation:

SAS Language Reference: Dictionary, SUM Function:
http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a000245953.htm
New Contributor BW
New Contributor
Posts: 2

Re: sum

Posted in reply to deleted_user
a refers to an array
a1 is the first element of the array
sum(a1,a2,a3,a4) can be shorted handed to sum(of a1-a4)
hope that answer your question
SAS Super FREQ
Posts: 8,864

Re: sum

Hi:
As a teacher, I am honor bound to add some SAS-related elaboration to the post about A1-A4 as being in ARRAY A.

In some languages, the list of variables or fields named A1-A4 WOULD automatically be an array reference to the array named A. And the array named A would, in some languages, be a physical data construct.

In SAS, however, an ARRAY is not a physical data construct. The name of the array is declared in an ARRAY statement (either in a DATA step program or in some of the STAT procedures that allow ARRAY references) and does not have to bear any relationship at all to the numbered (or unnumbered) variable list that defines the array members.

So, for example, these are all valid ARRAY declarations in a SAS DATA step program (for numeric variables):
[pre]
array a a1-a4;
array wombat a1-a4;
array unord a3 a1 a4 a2;
array lovelucy fred ethel lucy ricky;
[/pre]

Only the first ARRAY statement declares the variable name to be 'A'. In the above ARRAY statements, the references point to the following variables:
[pre]
Array Array Refers to
Name Reference SAS Variable
-------- ----------- -----------
A A(2) A2
WOMBAT WOMBAT(2) A2
UNORD UNORD(2) A1
LOVELUCY LOVELUCY(2) ETHEL
[/pre]

When a SAS dataset is not actively being used in a DATA step program, you will never see the declared array NAME (A, WOMBAT, UNORD, or LOVELUCY) in the descriptor portion of the SAS dataset (as with a PROC CONTENTS or a PROC DATASETS). You -will- see the variables, ALL the variables, in the descriptor portion of the dataset.

So, if your dataset contains numbered variables, such as A1, A2, A3, A4 or YR1999, YR2000, YR2001, YR2002, it sometimes becomes tedious to list all the variables one after the other in code. Many SAS statements, functions and options allow you to use variable lists (in a variety of forms), as shown in the documentation, as a referencing shortcut.

For example, if you use the SUM function, the use of 'OF' in the SUM function, as described here:
http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a000245953.htm

You could have:
[pre]
total = sum(a1, a2, a3, a4);
OR
total = sum(lucy, ricky, fred, ethel);
OR
total = sum(OF a1-a4);
OR
total=sum(OF a1-a4, a5, a6);
[/pre]

IF you had declared an ARRAY in a DATA step program, you might use a DO loop to accumulate or create a new variable from the members of an array. However, the original question was about the SUM function, so I'll end here. The bottom line is that numbered variables do not automatically mean that the numbered variables are in an ARRAY -- that is frequently one usage of numbered variables -- but not an automatic usage.

cynthia
Ask a Question
Discussion stats
  • 7 replies
  • 422 views
  • 0 likes
  • 5 in conversation