Home > Mobile >  Making simple calculations across rows and columns in SAS
Making simple calculations across rows and columns in SAS

Time:09-23

I have an issue with making calculations in SAS as an example I have the following data:

Type           amount
Axiom_Indlån    19966699113
Puljerneskontantindestående 133819901
Puljerne Andre passiver -9389117
Rap_Indlån  47501558321

I want to calculate the following:

 ('Rap_Indlån' - 'Puljerneskontantindestående' - 'Puljerne Andre passiver') - Axiom_Indlån

How do I achieve this ?

And how would I do it if it was columns instead of rows?

This is one of my big issues I hope you can point me in the right direction.

CodePudding user response:

Hard to tell what you are asking for since you have not shown an input or output datasets.

But it sounds like you just want to multiple some of the values by negative one before summing.
So if your dataset looks like this:

data have;
  infile cards dsd truncover;
  input name :$50. value;
cards;
Axiom_Indlån,19966699113
Puljerneskontantindestående,133819901
Puljerne Andre passiver,-9389117
Rap_Indlån,47501558321
;

You could get the total pretty easily in SQL for example.

proc sql;
  create table want as
    select sum(VALUE*case when (NAME in ('Rap_Indlån')) then 1 else -1 end) as TOTAL
    from HAVE
  ;
 quit;

CodePudding user response:

If you wanted to do it by columns, simply transpose and subtract as normal.

proc transpose data=have out=have_tpose;
    id name;
    var value;
run;

data want;
    set have_tpose;
    
    total = ('Rap_Indlån'n - 'Puljerneskontantindestående'n - 'Puljerne Andre passiver'n) - 'Axiom_Indlån'n;
run;
  • Related