i want to delete same id. Is there a way? please help me.. thank you..
ex)
original set fina set
id year x id year x
a 2000 2 --------> a 2000 2
a 2001 5 a 2001 5
b 2000 . c 2000 3
b 2001 5 c 2001 3
c 2000 3
c 2001 3
It seems you want to delete all rows of same ID YEAR, when IND is missing.
You may try next code:
proc sql
create table to_del as
select distinct ID, YEAR
where IND=.
from have
order by ID, YEAR;
quit;
data want;
merge have(in=inh)
del (in=ind);
by ID YEAR;
if inh and not ind;
run;
you can remove duplicates by using proc sort. But example you have given is not clear. can you elaborate your example, that is explain in brief, why you want to delete a particular id.
i will analyze by DIFFERENCE-IN-DIFFERENCES (DiD) analysis. and I will use BALANCED DATA SET. understand me?
id | YEAR | TIME | IND | TIME x IND | id | YEAR | TIME | IND | TIME x IND | |
a | 2000 | 0 | 0.23 | 0 | a | 2000 | 0 | 0.23 | 0 | |
a | 2001 | 1 | 0.22 | 0.22 | a | 2001 | 1 | 0.22 | 0.22 | |
b | 2000 | 0 | 0.43 | 0 | → | c | 2000 | 0 | 0.55 | 0 |
b | 2001 | 1 | . | . | c | 2001 | 1 | 33 | 33 | |
c | 2000 | 0 | 0.55 | 0 | d | 2000 | 0 | 0.25 | 0 | |
c | 2001 | 1 | 33 | 33 | d | 2001 | 1 | 0.4 | 0.4 | |
d | 2000 | 0 | 0.25 | 0 | ||||||
d | 2001 | 1 | 0.4 | 0.4 |
It seems you want to delete all rows of same ID YEAR, when IND is missing.
You may try next code:
proc sql
create table to_del as
select distinct ID, YEAR
where IND=.
from have
order by ID, YEAR;
quit;
data want;
merge have(in=inh)
del (in=ind);
by ID YEAR;
if inh and not ind;
run;
thank you so much!!
data have;
input id $ year x ;
cards ;
a 2000 2
a 2001 5
b 2000 .
b 2001 5
c 2000 3
c 2001 3
;
run;
proc sql;
select *
from have
group by id
haing nmiss(x)=0;
quit;
thank you very much!
It was a great help. thank you.
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.