Turn on suggestions

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

Showing results for

- Home
- /
- Programming
- /
- Programming
- /
- Issue with dataset + operator

Options

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

☑ This topic is **solved**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 06-23-2023 01:04 PM
(218 views)

```
data s2;
retain sum;
assign = sum;
sum + 1;
proc print; run;
```

*Anyone knows why here:*

assign=. whereas

sum=1

because when we apply the + operator with any missing value the final result should be. (missing)

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

If you use a variable as the target in a SUM statement then the variable will be retained and it will default to initialize to zero , UNLESS YOU TELL TO INITIALIZE TO SOMETHING ELSE.

Remove the RETAIN statement. Of tell it to initialize to zero instead of missing.

19 data s2; 20 retain sum; 21 assign = sum; 22 sum + 1; 23 put (_all_) (=); 24 run; sum=1 assign=. NOTE: The data set WORK.S2 has 1 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.03 seconds cpu time 0.04 seconds 25 data s2; 26 assign = sum; 27 sum + 1; 28 put (_all_) (=); 29 run; assign=0 sum=1 NOTE: The data set WORK.S2 has 1 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.03 seconds 30 data s2; 31 retain sum 100; 32 assign = sum; 33 sum + 1; 34 put (_all_) (=); 35 run; sum=101 assign=100 NOTE: The data set WORK.S2 has 1 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds

4 REPLIES 4

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

The SUM statement documentation says the variable (in this case SUM) is initialized to zero. So sum+1 is not missing.

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

There are three "sum" methods.

Sum Operator

Sum Statement

Sum Function

They each works slightly differently.

Sum Operator

Sum Statement

Sum Function

They each works slightly differently.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Please explain

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

If you use a variable as the target in a SUM statement then the variable will be retained and it will default to initialize to zero , UNLESS YOU TELL TO INITIALIZE TO SOMETHING ELSE.

Remove the RETAIN statement. Of tell it to initialize to zero instead of missing.

19 data s2; 20 retain sum; 21 assign = sum; 22 sum + 1; 23 put (_all_) (=); 24 run; sum=1 assign=. NOTE: The data set WORK.S2 has 1 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.03 seconds cpu time 0.04 seconds 25 data s2; 26 assign = sum; 27 sum + 1; 28 put (_all_) (=); 29 run; assign=0 sum=1 NOTE: The data set WORK.S2 has 1 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.03 seconds 30 data s2; 31 retain sum 100; 32 assign = sum; 33 sum + 1; 34 put (_all_) (=); 35 run; sum=101 assign=100 NOTE: The data set WORK.S2 has 1 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.