DATA Step, Macro, Functions and more


Posts: 0


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

Re: sum

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_;
Posts: 0

Re: sum

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

thanks in advance.
Posts: 0

Re: sum

can you explain me what is a "signal"?
Super Contributor
Super Contributor
Posts: 3,174

Re: sum

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

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

SAS Language Reference: Dictionary, SUM Function:
New Contributor BW
New Contributor
Posts: 2

Re: sum

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
Posts: 8,743

Re: sum

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):
array a a1-a4;
array wombat a1-a4;
array unord a3 a1 a4 a2;
array lovelucy fred ethel lucy ricky;

Only the first ARRAY statement declares the variable name to be 'A'. In the above ARRAY statements, the references point to the following variables:
Array Array Refers to
Name Reference SAS Variable
-------- ----------- -----------
A A(2) A2

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:

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

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.

Ask a Question
Discussion stats
  • 7 replies
  • 5 in conversation