0% found this document useful (0 votes)
56 views2 pages

Assignment Merging Data

The document discusses merging and combining stock market data from different sources. It shows how to import data from files, split datasets into subsets, append datasets together by observation number or variable value, and merge datasets based on common variables. The goal is to produce combined and filtered datasets containing only stocks that are part of certain indexes, or contained in one dataset but not the other.

Uploaded by

atma12321
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views2 pages

Assignment Merging Data

The document discusses merging and combining stock market data from different sources. It shows how to import data from files, split datasets into subsets, append datasets together by observation number or variable value, and merge datasets based on common variables. The goal is to produce combined and filtered datasets containing only stocks that are part of certain indexes, or contained in one dataset but not the other.

Uploaded by

atma12321
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

*******************Merging Data********************;

****to check the contents of the dataset add "proc print ;*run;*" after each data step statements ; data niftycodes; infile "E:..\Raw data\TXT\niftystocksdata.txt" input name :$42. NSECODE :$10. BSECODE ; run;

delimiter = "|";

proc import datafile='E:\....\Raw data\Excel\sensex stocks.xls' out=sensexstocks dbms=excel replace; run; ***********automatic variable _N_ counts the number of observations in the dataset; data temp1 temp2 temp3 temp4 temp5; set niftycodes; if _N_ < 10 then output temp1; else if _N_ <20 then output temp2; else if _N_ < 30 then output temp3; else if _N_ <40 then output temp4; else output temp5; run; *********************APPNEDING DATASETS; *data gets appended in the order of filename; data combineddata; set run; temp3 temp4 temp5 temp1 temp2;

*or*****************************; proc proc proc proc proc append append append append append data=temp1 data=temp2 data=temp3 data=temp4 data=temp5 base=comdata; base=comdata; base=comdata; base=comdata; base=comdata; run; run; run; run; run;

**** rerun the above five proc append commands again and see what happens; data noninterdata; set temp5 temp1; run; ******************* Interleaving data sets ******************; ***What If I want the appended data to be actually sorted by variable say BSECODE; proc sort data=temp1; by bsecode; proc sort data=temp2; by bsecode; proc sort data=temp5; by bsecode; data interdata; set run; temp5 temp2 temp1; by bsecode;

***COMBINING DATA SETS LEFT AND RIGHT;

data left; set niftycodes; keep name; run; data right; set niftycodes; DROP Name; run; data leftright; merge left right; run; *********************** Merging of ALL sorts**********; data sensexstocks; set sensexstocks; rename nse_scrip_code=nsecode; run; proc sort data=niftycodes; by nsecode; proc sort data=sensexstocks; by nsecode; data mergedfile; merge niftycodes sensexstocks; by nsecode; run; *** I only want all the stocks that are part of NIFTY or common stocks in both the files; data niftysensxstocks; merge niftycodes (in=nifty) sensexstocks(in=sensex); by nsecode; if nifty; if sensex; run; **which is the stock that is in sensex but not in NIFTY; data one; merge niftycodes (in=Nifty) sensexstocks(in=sensex); by nsecode; if sensex; if not nifty; run; ** which are the stocks that are in NIFTY but not in SENSEX:; data niftyonly ; merge niftycodes(in=nifty) sensexstocks(in=sensex); by nsecode; if nifty; if not sensex; run; *****ALRIGHTY YOU ARE READY TO COMPLETE YOUR FIRST PROGRAMMING ASSISGNEMENT******************************; *********ALL THE BEST********************************; and SENSEX:

You might also like