Using "Retain" with missing Values

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

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: 17,745

Re: Using "Retain" with missing Values

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

View solution in original post


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

Re: Using "Retain" with missing Values

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

Respected Advisor
Posts: 3,124

Re: Using "Retain" with missing Values

Or replacing

retain c 0;

c=c+b;

WITH

c+b;

Haikuo

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 157 views
  • 3 likes
  • 3 in conversation