Construct appropriate pre-and post- sample

Accepted Solution Solved
Reply
Highlighted
Contributor
Posts: 29
Accepted Solution

Construct appropriate pre-and post- sample

Hi,

 

I want to restrict my sample to have quasi-balanced pre-and post- observations..

 

For example,

 

Data original;

input supplier customer year post;

datalines;

1001 8001 2000 1

1001 8001 2001 1

1002 8006 1995 0

1002 8006 1996 0

1002 8006 1997 1

1002 8006 1998 1

1002 8006 1999 1

1003 8008 2005 0

1003 8008 2006 0

1003 8009 2006 0

1003 8009 2007 1

;

run;

 

I want to keep observations having both pre-and post- period. That is, I want to exclude observations having only (Post = 0s) or (Post = 1s).

 

So, I want to have like this datasets.. after coding;

 

Data hope;

input supplier customer year post;

datalines;

 

1002 8006 1995 0

1002 8006 1996 0

1002 8006 1997 1

1002 8006 1998 1

1002 8006 1999 1

 

1003 8009 2006 0

1003 8009 2007 1

;

run;

 

Thank you!

 


Accepted Solutions
Solution
‎04-16-2018 02:39 PM
Super User
Posts: 2,061

Re: Construct appropriate pre-and post- sample

same as PG, did PG miss customer in group by?

 

Data original;

input supplier customer year post;

datalines;
1001 8001 2000 1
1001 8001 2001 1
1002 8006 1995 0
1002 8006 1996 0
1002 8006 1997 1
1002 8006 1998 1
1002 8006 1999 1
1003 8008 2005 0
1003 8008 2006 0
1003 8009 2006 0
1003 8009 2007 1
;

run;

 
proc sql;
create table hope as
select * 
from original
group by supplier,customer
having count(distinct post) = 2
order by supplier, year;
quit;

View solution in original post


All Replies
Esteemed Advisor
Posts: 5,624

Re: Construct appropriate pre-and post- sample

select the suppliers with two post values:

 

proc sql;
create table hope as
select * 
from original
group by supplier
having count(distinct post) = 2;
quit;
PG
Solution
‎04-16-2018 02:39 PM
Super User
Posts: 2,061

Re: Construct appropriate pre-and post- sample

same as PG, did PG miss customer in group by?

 

Data original;

input supplier customer year post;

datalines;
1001 8001 2000 1
1001 8001 2001 1
1002 8006 1995 0
1002 8006 1996 0
1002 8006 1997 1
1002 8006 1998 1
1002 8006 1999 1
1003 8008 2005 0
1003 8008 2006 0
1003 8009 2006 0
1003 8009 2007 1
;

run;

 
proc sql;
create table hope as
select * 
from original
group by supplier,customer
having count(distinct post) = 2
order by supplier, year;
quit;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 114 views
  • 0 likes
  • 3 in conversation