turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- sum

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-31-2009 12:40 AM

a=3+.;

b=.+.;

c=sum(3,.);

d=sum(.,.);

what will the result? how it comes? please explain

Thanks in advance.

b=.+.;

c=sum(3,.);

d=sum(.,.);

what will the result? how it comes? please explain

Thanks in advance.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-31-2009 02:41 AM

Hi:

To find the results, you need to put the statements in a DATA step program. The program code and results are shown below from the SAS log:

[pre]

1077 data testsum;

1078 a=3+.;

1079 b=.+.;

1080 c=sum(3,.);

1081 d=sum(.,.);

1082 put _all_;

1083 run;

NOTE: Missing values were generated as a result of performing an operation on missing values.

Each place is given by: (Number of times) at (Line)Column).

1078:4 1079:4

a=. b=. c=3 d=. _ERROR_=0 _N_=1

NOTE: Missing values were generated as a result of performing an operation on missing values.

Each place is given by: (Number of times) at (Line)Column).

1 at 1081:3

NOTE: The data set WORK.TESTSUM has 1 observations and 4 variables.

NOTE: DATA statement used (Total process time):

real time 0.07 seconds

cpu time 0.00 seconds

[/pre]

The SUM function returns the sum of non-missing values, as clearly explained in the documentation:

http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a000245953.htm

The documentation on assignment statements also explains how missing values are treated when you work with arithmetic operators in an assignment statement:

http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001334675.htm

In particular, look for the section entitled "Propagation of MIssing Values", where it states that:

"When you use a missing value in an arithmetic expression, SAS sets the result of the expression to missing. If you use that result in another expression, the next result is also missing. In SAS, this method of treating missing values is called propagation of missing values."

cynthia

To find the results, you need to put the statements in a DATA step program. The program code and results are shown below from the SAS log:

[pre]

1077 data testsum;

1078 a=3+.;

1079 b=.+.;

1080 c=sum(3,.);

1081 d=sum(.,.);

1082 put _all_;

1083 run;

NOTE: Missing values were generated as a result of performing an operation on missing values.

Each place is given by: (Number of times) at (Line)Column).

1078:4 1079:4

a=. b=. c=3 d=. _ERROR_=0 _N_=1

NOTE: Missing values were generated as a result of performing an operation on missing values.

Each place is given by: (Number of times) at (Line)Column).

1 at 1081:3

NOTE: The data set WORK.TESTSUM has 1 observations and 4 variables.

NOTE: DATA statement used (Total process time):

real time 0.07 seconds

cpu time 0.00 seconds

[/pre]

The SUM function returns the sum of non-missing values, as clearly explained in the documentation:

http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a000245953.htm

The documentation on assignment statements also explains how missing values are treated when you work with arithmetic operators in an assignment statement:

http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001334675.htm

In particular, look for the section entitled "Propagation of MIssing Values", where it states that:

"When you use a missing value in an arithmetic expression, SAS sets the result of the expression to missing. If you use that result in another expression, the next result is also missing. In SAS, this method of treating missing values is called propagation of missing values."

cynthia