A CNTLIN dataset would just be a way to define a format. Please show what format you would define for given example and how you would use it.
Not sure I get the logic here.
Is the goal to flag any observation where either SSN that has more than one ID associated with it?
So perhaps just find the SSN that have multiple IDs associated and make for format that just has those values of SSN?
data DS_To_Flag;
input ID SSN $ COMP_SSN $;
datalines;
123 999 0
333 666 987
444 765 0
9996 987 0
876 8889 999
777 8889 0
;
proc transpose data=ds_to_flag out=ssn(rename=(col1=ssn) where=(ssn not in ('0',' '))) name=type ;
by id notsorted;
var ssn comp_ssn;
run;
proc print;
run;
proc sql ;
create table cntlin as
select 'ssndup' as fmtname
, 'C' as type
, ssn as start
, 'Y' as label
from ssn
group by 1,2,3,4
having count(*) > 1
;
quit;
proc format cntlin=cntlin fmtlib;
run;
data want ;
set ds_to_flag;
if put(ssn,$ssndup.)='Y' or put(comp_ssn,$ssndup.)='Y' then multi_flag='Y';
else multi_flag='N';
run;
proc print;
run;
Please provide data in usable form: a data step using datalines or proc sql with insert.
A CNTLIN dataset would just be a way to define a format. Please show what format you would define for given example and how you would use it.
Not sure I get the logic here.
Is the goal to flag any observation where either SSN that has more than one ID associated with it?
So perhaps just find the SSN that have multiple IDs associated and make for format that just has those values of SSN?
data DS_To_Flag;
input ID SSN $ COMP_SSN $;
datalines;
123 999 0
333 666 987
444 765 0
9996 987 0
876 8889 999
777 8889 0
;
proc transpose data=ds_to_flag out=ssn(rename=(col1=ssn) where=(ssn not in ('0',' '))) name=type ;
by id notsorted;
var ssn comp_ssn;
run;
proc print;
run;
proc sql ;
create table cntlin as
select 'ssndup' as fmtname
, 'C' as type
, ssn as start
, 'Y' as label
from ssn
group by 1,2,3,4
having count(*) > 1
;
quit;
proc format cntlin=cntlin fmtlib;
run;
data want ;
set ds_to_flag;
if put(ssn,$ssndup.)='Y' or put(comp_ssn,$ssndup.)='Y' then multi_flag='Y';
else multi_flag='N';
run;
proc print;
run;
Thank You Tom..
Yes, the resolution provided did work very well...you got the logic right.
ID is unique and however, the value of SSN having found multiples either in SSN or COMP_SSN...or COMP_SSN having found multiples either in SSN or COMP_SSN then the Multi_Flag is Y..
I never had success using CNTLIN and your steps did make me understand it and Data Transpose is which I never though off..
Tom, thank you so much... You made it very clear.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.