Skip to content

Instantly share code, notes, and snippets.

/* Run the optimization */
proc optmodel;
set patterns = 1..&num_patterns;
set cuts = 1..&num_cuts;
number choices {patterns, cuts};
number prices {patterns};
number targets {cuts};
data testset;
input @1 level @3 county $3. @7 degree $3. @11 num 3. @15 salary 5.;
datalines;
3 WAY B 100 30000
3 WAY M 25 50000
3 WAY P 1 70000
3 FAR B 200 30000
3 FAR M 50 50000
3 FAR P 2 70000
/* "Primary" suppression - hide all values equal to 1 */
data testset;
set testset;
if num = 1 then num = .;
run;
/* Code below here should be run repeatedly until the data no longer changes... */
/* Suppress across the county dimension */
/* Put the data in order of degrees, and ascending number of citizens (missing sorts low in SAS) */
proc sort data = testset;
by level degree num;
run;
/* Hide salaries if number is hidden... */
data testset;
set testset;
if num = . then salary = .;
run;
/* target_data is the data set you want to suppress
target_var is the variable you want to suppress
dimensions is a pipe-separated list of dimensions to suppress
cutoff is the highest value you want to suppress */
%macro suppress(target_data, target_var, dimensions, cutoff);
/* Count the number of dimensions we're working with */
%let num_dims = %eval(%sysfunc(count(&dimensions, |)) + 1);
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;
proc means noprint data = names_raw;
class first_name last_name race;
var number;
data testset;
input @1 county $3. @5 degree $3. @9 num 3. @13 salary 5.;
datalines;
WAY B 100 30000
WAY M 25 50000
WAY P 1 70000
FAR B 200 30000
FAR M 50 50000
FAR P 2 70000
/* We need constraints for every combination of dimensions you can build by leaving out one dimension at a time.
This is pretty simple in a 2-dimensional dataset. */
proc sql;
create table
levels
/* Constraints across the degree dimension */
as select distinct
/* Merge our raw data with our constraint categories to determine which constraints apply to which data points */
proc sql;
create table
joined
as select
t.*,
con,
case when
(t.county = l.county and l.degree = 'dummy' and t.degree ~= 'ALL')