Looking at your data structure, you have a quality control scenario where human reviewers are suggesting NAICS code corrections, and you need to understand the impact on your internal industry groupings.
Here are key analyses to perform:
1. Change Impact Summary
proc freq data=yourdata;
tables naics_orig*naics_sug / missing norow nocol nopercent;
title "NAICS Code Changes Overview";
run;
data change_summary;
set yourdata;
naics_changed = (naics_orig ne naics_sug);
mapping_changed = (map_orig ne map_sug);
if naics_changed=0 then change_type = "No Change";
else if naics_changed=1 and mapping_changed=0 then change_type = "NAICS Changed, Mapping Same";
else if naics_changed=1 and mapping_changed=1 then change_type = "Both Changed";
run;
proc freq data=change_summary;
tables change_type;
run;
2. Mapping Consistency Check
/* Find cases where NAICS changed but mapping stayed same */
proc print data=yourdata;
where naics_orig ne naics_sug and map_orig = map_sug;
title "NAICS Changed but Industry Group Unchanged";
run;
/* Find cases where same NAICS maps to different groups */
proc sql;
select naics_orig, map_orig, count(*) as freq
from (select distinct naics_orig, map_orig from yourdata
union
select distinct naics_sug as naics_orig, map_sug as map_orig from yourdata)
group by naics_orig
having count(distinct map_orig) > 1;
quit;
3. Crosswalk Validation
/* Check if all NAICS codes exist in crosswalk */
proc sql;
create table missing_codes as
select distinct naics_sug as naics_code, 'Suggested' as source
from yourdata
where naics_sug not in (select naics from AB)
union
select distinct naics_orig as naics_code, 'Original' as source
from yourdata
where naics_orig not in (select naics from AB);
quit;
4. Change Pattern Analysis
proc sql;
create table change_patterns as
select naics_orig, naics_sug, map_orig, map_sug, count(*) as frequency
from yourdata
where naics_orig ne naics_sug
group by naics_orig, naics_sug, map_orig, map_sug
order by frequency desc;
quit;
5. Quality Metrics
proc sql;
select
count(*) as total_records,
sum(naics_orig ne naics_sug) as naics_changes,
sum(map_orig ne map_sug) as mapping_changes,
calculated naics_changes / calculated total_records as pct_naics_changed format=percent8.1,
calculated mapping_changes / calculated total_records as pct_mapping_changed format=percent8.1
from yourdata;
quit;
These analyses will reveal the scope of changes, identify potential data quality issues, and help you understand whether the human suggestions are improving or complicating your industry classifications.