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

 I  have two data file. one file has the list of 5534 companies and other file as the companies which of part of S&P CNX Nifty-50 Index. 

i have to create a dummy variable in file one which equals to '1' if the company belong to S&P CNX Nifty-50 Index or otherwise '0'. 

please suggest me a SAS code to create a dummy variable as discussed above. 

the following is the format of the two data files. 

File one

Company Name
20 Microns Ltd.
3I Infotech Ltd.
3M India Ltd.
3P Land Holdings Ltd.
3Rd Rock Multimedia Ltd.
52 Weeks Entertainment Ltd.
5Paisa Capital Ltd.
63 Moons Technologies Ltd.
7Nr Retail Ltd.
7Seas Entertainment Ltd.
8K Miles Software Services Ltd.
A & M Febcon Ltd.
A & M Jumbo Bags Ltd.
A 2 Z Infra Engg. Ltd.
A A R Commercial Co. Ltd.

 

file two 

Company Name
A B G Shipyard Ltd.
A K Spintex Ltd.
Cochin Malabar Estates & Inds. Ltd.
Dabur India Ltd.
Denis Chem Lab Ltd.
Jindal Hotels Ltd.

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

So all the companies should have dummy = 0 in this case, correct?

 

Is your actual data sorted?

View solution in original post

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

So all the companies should have dummy = 0 in this case, correct?

 

Is your actual data sorted?

hhinohar
Quartz | Level 8

I don't see match in any company for either file.Anyway below is a code.

*list of 5534 companies;
data one;
length comp $ 100;
input comp $ &;
datalines;
20 Microns Ltd.
3I Infotech Ltd.
3M India Ltd.
3P Land Holdings Ltd.
3Rd Rock Multimedia Ltd.
52 Weeks Entertainment Ltd.
5Paisa Capital Ltd.
63 Moons Technologies Ltd.
7Nr Retail Ltd.
7Seas Entertainment Ltd.
8K Miles Software Services Ltd.
A & M Febcon Ltd.
A & M Jumbo Bags Ltd.
A 2 Z Infra Engg. Ltd.
A A R Commercial Co. Ltd.
;
run;

*S&P CNX Nifty-50 Index;
data two;
length comp $ 100;
input comp $ &;
datalines;
A B G Shipyard Ltd.
A K Spintex Ltd.
Cochin Malabar Estates & Inds. Ltd.
Dabur India Ltd.
Denis Chem Lab Ltd.
Jindal Hotels Ltd.
;
run;

data three;
	*primary dataset;
	set one;
	if _N_=1 then do;
		if 0 then set two;
		dcl hash h(dataset:"two");
		h.definekey("comp");
		h.definedone();
	end;
	*look up;
	_iorc_=h.check();
	if _iorc_ ne 0 then dummy=0;
	else dummy=1;
run;
srikanthyadav44
Quartz | Level 8
thanks. the code is working
Kurt_Bremser
Super User

Do it with a hash:

data want;
set table1;
if _n_ = 1
then do;
  declare hash n50 (dataset:"table2");
  n50.definekey("comp_name");
  n50.definedone();
end;
dummyvar = (n50.check() = 0);
run;
PeterClemmensen
Tourmaline | Level 20

If they are sorted, see if you can use this as a template

 

data one;
input company $;
datalines;
comp1
comp2
comp3
comp4
;

data two;
input company $;
datalines;
comp1
comp3
;

data want;
   merge one two(in=b);
   by company;
   dummy = b;
run;
PeterClemmensen
Tourmaline | Level 20

If they're not sorted, do this

 

data want;
   if _N_ = 1 then do;
      dcl hash h (dataset : 'two');
      h.definekey('company');
      h.definedone();
   end;

   set one;
   
   dummy = (h.check() = 0);

run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 6 replies
  • 974 views
  • 2 likes
  • 4 in conversation