BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.

Dear all 

greetings of the day 

 

i have my dataset in the following format 

Company_Nameyearmcapindustry_codeMCAPRANKESG reporting
Oil & Natural Gas Corpn. Ltd.20102,349,76561011
Oil India Ltd.2010277,16061020
Selan Exploration Technology Ltd.20106,60461030
Bharat Heavy Electricals Ltd.20101,168,998251311
Godrej Consumer Products Ltd.2011118,2563410
Tata Chemicals Ltd.201186,6623420
Piramal Enterprises Ltd.201169,9963431
H M T Ltd.201145,0323440
K S K Energy Ventures Ltd.201137,6363450
B A S F India Ltd.201125,6923460
Peninsula Land Ltd.201116,5503470
Texmaco Rail & Engg. Ltd.201112,7293480
Alembic Ltd.20119,7603490

i have to identify the peer group companies. the criteria are as follows

if the company is making ESG reporting, ( i.e., value is equal to '1'), identify the companies which are closer to ESG reporting companies based on their MCAP(market capitalization) as peer companies within each industry code. the closeness should be just below the ESG company MCAP and just above the ESG company MCAP in two levels 

in some industry groups, we cannot find peer companies just above the MCAP of ESG companies, and also in some industries, only one company. in such case no peer company

 

the output should be in the following format

company_nameyearindustry_codePeer01_Low Peer01_highPeer02_lowPeer02_high
Oil & Natural Gas Corpn. Ltd.2010610Oil India Ltd.0Selan Exploration Technology Ltd.0
Bharat Heavy Electricals Ltd.201025130000
Piramal Enterprises Ltd.201134H M T Ltd.Tata Chemicals Ltd.K S K Energy Ventures Ltd.Godrej Consumer Products Ltd.

 

Peer01_low = means immediately succeeding peer company based on MCAP within the industry 

Peer01_high =means immediately preceding peer company based on MCAP within the industry

Peer02_low=means next to immediately succeeding peer company based on MCAP within the industry 

Peer02_high =means prior  to immediately preceding peer company based on MCAP within the industry

 

in the above table for 'Oil & Natural Gas Corpn. Ltd'  peer01_high is zero, it means no peer company in the industry with a market capitalization of more than ESG Company 

 

hope i mentioned the conditions clearly. if any clarity is required on the conditions, please let me know.

i could not genet the data lines, so, i am attaching the sample company in . CSV format. 

 

PLEASE HELP ME OUT IN WRITING THE SAS QUERY.  THANKING YOU IN ADVANCE

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

If variable RANK is reliable:

 

data have;
length name $32;
input Name & year mcap code RANK ESG;
datalines;
Oil & Natural Gas Corpn. Ltd.   2010    2349765 610 1   1
Oil India Ltd.  2010    277160  610 2   0
Selan Exploration Technology Ltd.   2010    6604    610 3   0
Bharat Heavy Electricals Ltd.   2010    1168998 2513    1   1
Godrej Consumer Products Ltd.   2011    118256  34  1   0
Tata Chemicals Ltd.  2011    86662   34  2   0
Piramal Enterprises Ltd.    2011    69996   34  3   1
H M T Ltd.  2011    45032   34  4   0
K S K Energy Ventures Ltd.  2011    37636   34  5   0
B A S F India Ltd.  2011    25692   34  6   0
Peninsula Land Ltd.  2011    16550   34  7   0
Texmaco Rail & Engg. Ltd.   2011    12729   34  8   0
Alembic Ltd.    2011    9760    34  9   0
;

proc sql;
create table want as
select 
    a.name, a.year, a.code,
    b.name as low1, c.name as high1, d.name as low2, e.name as high2
from 
    have as a left join
    have as b on a.code=b.code and a.year=b.year and a.rank=b.rank-1 left join
    have as c on a.code=c.code and a.year=c.year and a.rank=c.rank+1 left join
    have as d on a.code=d.code and a.year=d.year and a.rank=d.rank-2 left join
    have as e on a.code=e.code and a.year=e.year and a.rank=e.rank+2
where a.ESG=1;
select * from want;
quit;

PGStats_0-1668228603441.png

 

PG

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

If variable RANK is reliable:

 

data have;
length name $32;
input Name & year mcap code RANK ESG;
datalines;
Oil & Natural Gas Corpn. Ltd.   2010    2349765 610 1   1
Oil India Ltd.  2010    277160  610 2   0
Selan Exploration Technology Ltd.   2010    6604    610 3   0
Bharat Heavy Electricals Ltd.   2010    1168998 2513    1   1
Godrej Consumer Products Ltd.   2011    118256  34  1   0
Tata Chemicals Ltd.  2011    86662   34  2   0
Piramal Enterprises Ltd.    2011    69996   34  3   1
H M T Ltd.  2011    45032   34  4   0
K S K Energy Ventures Ltd.  2011    37636   34  5   0
B A S F India Ltd.  2011    25692   34  6   0
Peninsula Land Ltd.  2011    16550   34  7   0
Texmaco Rail & Engg. Ltd.   2011    12729   34  8   0
Alembic Ltd.    2011    9760    34  9   0
;

proc sql;
create table want as
select 
    a.name, a.year, a.code,
    b.name as low1, c.name as high1, d.name as low2, e.name as high2
from 
    have as a left join
    have as b on a.code=b.code and a.year=b.year and a.rank=b.rank-1 left join
    have as c on a.code=c.code and a.year=c.year and a.rank=c.rank+1 left join
    have as d on a.code=d.code and a.year=d.year and a.rank=d.rank-2 left join
    have as e on a.code=e.code and a.year=e.year and a.rank=e.rank+2
where a.ESG=1;
select * from want;
quit;

PGStats_0-1668228603441.png

 

PG
srikanthyadav44
Quartz | Level 8
thanks a lot . the CODE is working.
i have to extend the code further to do further analysis.
i posting the details.
could you please help me out

thanking you in advance

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 594 views
  • 0 likes
  • 2 in conversation