BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hkim3677
Calcite | Level 5

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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

2 REPLIES 2
PGStats
Opal | Level 21

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
novinosrin
Tourmaline | Level 20

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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