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

Here is my updated code and it works actually well. I will post below a diagram to show what I was doing. 

DATA have;
	INPUT Mgrno Group ID Industry $ Source;
	DATALINES; 
	9999 1 00462610 1842 A
	9999 1 01737210 1842 A
	9999 1 12690310 2832 A
	8888 1 12690310 2832 T
	8888 1 12690311 2832 T
	8888 1 37158620 2124 T
	9999 1 23298321 4238 A
	9999 1 53228424 4238 A
	8888 1 53228424 4238 T
	8888 1 23298321 4238 T
	9999 1 12290311 1233 A
	8888 1 01737211 1233 T
	8888 1 99998881 1233 T
	7777 2 12690310 2832 A
	3333 2 32690311 2832 T
	7777 2 37158620 2124 A
	7777 2 38138222 3321 A
	3333 2 44134422 3321 T
	7777 2 53228424 4238 A
	3333 2 77233421 4238 T
	3333 2 12290311 1233 T
	3333 2 93234320 1333 T
;
RUN;

proc sort data=work.have nouniquekeys uniqueout=singles out=dup;
	by group id;
quit;


proc sort data=work.have out=list_noduplicates nodupkey;
	by group id;
quit;



data both;
	set dup;
	cont=1;
run;

*The firms controlled by both managers are control;
proc sql;
	create table distinct_both as
	select distinct group, industry, 1 as control
	from both;
quit;


*Here I am selecting the Managers with a Source=A since I will compare the 
firms this Manager controls with the firms the other Manager controls. T
stands for Target and A for Acquirer.;
data all_acq;
	set work.list_noduplicates;
	if Source='A';
run;

*Here I am selecting the Managers with a Source=T since I will compare the 
firms this Manager controls with the firms the other Manager controls;
data all_tar;
	set work.list_noduplicates;
	if Source='T';
run;



*Distinct cases start here, first compare distinct industries of target to 
all industries of the acquirer;

data distinct_tar;
	set singles;
	if source='T';
	distinct_tar=1;
	industry_target=industry;
	cusip_tar=ncusip;
run;

proc sql;
	create table treated_tar_V1 as 
	select * 
	from all_acq as a 
	left join distinct_tar as b 
	on a.industry=b.industry_target and a.group=b.group;
quit;

*These are some of the treated firms;
data treated_tar_V2(keep=group industry);
	set treated_tar_V1;
	if industry_target^=.;
run;

proc sort data=treated_tar_V2 out=distinct_target nodupkey;
	by group industry;
run;

*Second compare distinct firms controlled only by acquirer to all firms controlled by target;

data distinct_acq;
	set singles;
	if source='A';
	distinct_acq=1;
	industry_acq=industry;
	cusip_acq=ncusip;
run;

proc sql;
	create table treated_acq_V1 as 
	select * 
	from all_tar as a 
	left join distinct_acq as b 
	on a.industry=b.industry_acq and a.group=b.group;
quit;

*These are the treated firms;
data treated_acq_V2(keep=group industry);
	set treated_acq_V1;
	if industry_acq^=.;
run;

proc sort data=treated_acq_V2 nodupkey;
	by group industry;
run;


data all_treated(keep=group industry treated);
	set distinct_both treated_tar_V2 treated_acq_V2;
	treated=1;
run;



proc sql;
	create table all_treated_distinct as 
	select distinct group, industry, 1 as treated
	from all_treated;
quit;
Shmuel
Garnet | Level 18

@Yegen you are fast. 

I believe that the most users in this forum are essentially interested in SAS code "how to do" and in the solutions.

After assigning the Accepted Solution, most of them will not enter and read the long code, unless there is a new

"problem".

 

I am glad to help but I think there is no need to post yours full solution. As I said - unless you ask for somthing new

like help or improvement.

 

Personally, for me it was difficult to follow the full code.

 

BTW, it may be more efficient to ask for specific SAS help through this forum than by private message. 

 

Yegen
Pyrite | Level 9

Sounds good, @Shmuel. Maybe I will post a new question and ask whether there could be a more efficient code compared to mine. Thanks for this helpful suggestion. 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 17 replies
  • 2271 views
  • 10 likes
  • 3 in conversation