/*Assign a library*/ libname saskurs "U:\sas1011"; /* Change to appropriate directory */ /********************************************************************************* Reading in data using a data step *********************************************************************************/ data abx; INFILE 'U:\sas1011\abx.txt' delimiter=',' FIRSTOBS=2 ; /* Change to appropriate directory */ INPUT event_d event_t bid bid_vol ask ask_vol ticker $; format event_d date8. event_t time8.; /*Format and label the variables*/ label bid='bidprice' ask='askprice' event_d ='Date' event_t='Time' bid_vol='Bid volume' ask_vol='ask volume' ticker ='ticker'; run; data aby; INFILE 'U:\sas1011\aby.txt' delimiter=',' FIRSTOBS=2 ; /* Change to appropriate directory */ INPUT event_d event_t bid bid_vol ask ask_vol ticker $; format event_d date8. event_t time8.; label bid='bidprice' ask='askprice' event_d ='Date' event_t='Time' bid_vol='Bid volume' ask_vol='ask volume' ticker ='ticker'; run; /********************************************************************************* Reading in data using proc import *********************************************************************************/ proc import datafile='U:\sas1011\aby.txt' out=saskurs.abx2 DBMS=Tab replace; delimiter=','; label bid='bidprice' ask='askprice' event_d ='Date' event_t='Time' bid_vol='Bid volume' ask_vol='ask volume' ticker ='ticker'; run; /********************************************************************************* Data step to calculate midquotes and log midquotes *********************************************************************************/ data temp; set abx; midquote=(bid+ask)/2; lmidquote=log(midquote); drop ticker; /*drops a variable from a data set (there is also a "keep" statement)*/ run; /********************************************************************************* Examples for if condition - *********************************************************************************/ data temp; set temp; if bid_vol gt 100 then x=1; run; data temp; set temp; /*if bid_vol gt 100 then output;*/ Where bid_vol gt 100; run; /********************************************************************************* Example for PROC MEANS *********************************************************************************/ PROC MEANS data=temp noprint; var midquote lmidquote; /*by xxx; no by statement here*/ output out = tempmeans mean=midqmean logmidqmean; run; /********************************************************************************* Example for PROC SORT *********************************************************************************/ proc sort data=temp out=temp; by bid_vol; /*sorts by bid volume ascending (default) */ run; /********************************************************************************* Example for PROC CORR *********************************************************************************/ PROC CORR data=temp outp=corr; * choose variables for which correlations should be computed; var bid; with ask; * choose group variable ; /*by xxx;no by statement here*/ run; /********************************************************************************* Example for PROC FREQ *********************************************************************************/ PROC FREQ data=temp; * choose variables for which frequencies should be computed; tables bid/ out=freqs; * choose group variable; /*by xxx; no by variable here*/ run;