DATA Step, Macro, Functions and more

avoiding missing values

Reply
Contributor
Posts: 70

avoiding missing values

Hi all

         i have a one dataset with two variables cost,vat as follows

                        data x;

                        input cost vat;

                        datalines;

                         1000    100

                         5000    500

                         10000    .

                          .           .

                          ;

Now i want to add these two variables and addition of these two variables in new variable ADDITION and i dont want missing values in these variable.

Thanks &Regards

rawindarreddy

Frequent Contributor
Posts: 138

Re: avoiding missing values

use sum function.

Super Contributor
Posts: 349

Re: avoiding missing values

Hi,

Try this..Hope it helps

   data x;

    input cost vat;

  x=sum(cost,vat);

  if x ne .;

    datalines;

    1000    100

    5000    500

    10000    .

    .        .

    ;

  run;

Thanks,

Shiva

Super User
Posts: 10,460

Re: avoiding missing values

If all arguments to SUM function are missing it will still return missing.

The only option as I can see it, depending on why the missing are objectionable in the data, are to remove the record from the output or assign a specific value such as 0 if both variables are missing.

Contributor
Posts: 45

Re: avoiding missing values

you can add a 0 as one of the parameters in SUM to prevent returning a missing value -- SUM(0,cost,vat)

Ask a Question
Discussion stats
  • 4 replies
  • 265 views
  • 0 likes
  • 5 in conversation