PING  0.9
Statistical data handling and processing in production environment
silc_hsum_of_pvar

Sum personal (P) variable(s) over households (i.e., by row and columns).

%silc_hsum_of_pvar(yyyy, odsn=, ids=, var=, rvar=, ovar=, by=, lib=pdb, olib=WORK);

Arguments

  • yyyy : reference year;
  • ids : (option) type of input dataset; default: ids=P;
  • var : name of variable on which the sum is calculated;
  • by : list of variables used for GROUP BY condition in SQL statement; by default: by=PB010 PB020 PHID is used;
  • ilib : (option) name of the input library; by default: ilib=pdb.

Returns

  • odsn : (option) name of the output dataset (in WORK library); by default: odsn=HSUM;
  • ovar : (option) sum variable; by default: ovar=hsum;
  • rvar : (option) sumrow P variables ;by default: rvar=Ptot;
  • olib : (option) name of the output library; by default: olib=WORK.

Examples

Let us consider the test dataset #45: DB020 | DB010 | RB030 |EQ_INC20 | RB050a :-—:|:--—:|-------—:-----—:|------— BE | 2015 | 3310 | 10 | 10 BE | 2015 | 3311 | 10 | 10 BE | 2015 | 3312 | 10 | 10 BE | 2015 | 4434 | 20 | 20

and run the macro:

%silc_hsum_of_pvar;

which updates QUANTILE with the following table:

DB020 DB010 RB030 EQ_INC20 RB050a QUINTILE QUANTILE
BE 2015 3310 10 10 1 QUINTILE 1
BE 2015 3311 10 10 1 QUINTILE 1

Run macro %_example_income_quantile for more examples.

Note

In short, the macro runs the following PROC SQL procedure:

PROC SQL noprint;
CREATE TABLE &olib..&_dsn AS
SELECT
input.*,
%if %macro_isblank(Pvar) EQ 0 %then %do;
sum(&_Pvar,0) as Ptot,
%end;
sum(calculated Ptot) as &ovar
FROM Ppdb.&Pds as input
GROUP BY &_by;
QUIT;

See also

%ds_isempty, %lib_check, %var_check, SORT.