Assignment Merging Data
Assignment 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;
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: