## Using "Retain" with missing Values

Solved
Occasional Contributor
Posts: 14

# Using "Retain" with missing Values

Hi,

There is the .txt file "Text" as follow:

----|---10---|---

1901 2

1905 1

1910 6

1925 .

1941 1

And the code:

data want;

infile 'Text path';

input a b;

retain c 0;

c=c+b;

run;

The result for want is:

a         b       c

1901    2       2

1905    1       3

1910    6       9

1925    .        .

1941    1       .

But, what I realy want is:

a         b       c

1901    2       2

1905    1       3

1910    6       9

1925    .        9

1941    1       10

How should I proceed?

Thanks!

Accepted Solutions
Solution
‎07-22-2013 04:29 PM
Super User
Posts: 23,776

## Re: Using "Retain" with missing Values

Try replacing c=c+b with c=sum(c, b);

All Replies
Solution
‎07-22-2013 04:29 PM
Super User
Posts: 23,776

## Re: Using "Retain" with missing Values

Try replacing c=c+b with c=sum(c, b);

Posts: 3,167

## Re: Using "Retain" with missing Values

Or replacing

retain c 0;

c=c+b;

WITH

c+b;

Haikuo

🔒 This topic is solved and locked.