Skip to content

Instantly share code, notes, and snippets.

@daynebatten
Created May 31, 2015 13:27
Show Gist options
  • Select an option

  • Save daynebatten/5c66b4fc6327a9638206 to your computer and use it in GitHub Desktop.

Select an option

Save daynebatten/5c66b4fc6327a9638206 to your computer and use it in GitHub Desktop.
/* Read in the raw names data */
data names_raw;
infile "C:\Users\dbatten\Desktop\Name Data.csv" dlm = ',' dsd truncover lrecl = 1000;
input first_name :$50. last_name :$50. race :$3. number :5.;
run;
/* Aggreate it at every possible level */
proc means noprint data = names_raw;
class first_name last_name race;
var number;
output out = names(keep = _type_ first_name last_name race number rename = (_type_ = level)) sum = number;
run;
/* Switch the nulls coming out of PROC MEANS to 'ALL' for convenience */
/* Also, create two copoies - one to suppress with the heuristic, one optimally */
data names names_supp names_opt;
set names;
if first_name = ' ' then first_name = 'ALL';
if last_name = ' ' then last_name = 'ALL';
if race = ' ' then race = 'ALL';
run;
/* Run both suppression algorithms */
%suppress(names_supp,number,first_name|last_name|race,3);
%opt_suppress(names_opt,number,first_name|last_name|race,3);
/* Calculate the number of cells suppressed */
proc sql;
select
sum(case when s.number is null then n.number else 0 end) as heuristic_suppressed,
sum(case when o.number is null the n.number else 0 end) as optimal_suppressed,
sum(n.number) as total_N
from
names as n
left join
names_supp as s
on
n.first_name = s.first_name
and n.last_name = s.last_name
and n.race = s.race
left join
names_opt as o
on
n.first_name = o.first_name
and n.last_name = o.last_name
and n.race = o.race;
quit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment