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. |
So all the companies should have dummy = 0 in this case, correct?
Is your actual data sorted?
So all the companies should have dummy = 0 in this case, correct?
Is your actual data sorted?
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;
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;
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;
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;
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!
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.