How To select All Rows from a SAS data set that Match at least one value in another SAS Data set -
i trying read ticker names of 100 stocks / etfs 1 csv file. have 2 csv files, 1 contains data stocks / etfs on 90 day period. second contains name of 100 stock/etf tickers interested in selecting. below code, work.etfnames 1 column data set contains 100 etf names want select fulldata. how can use list of names correctly select desired data. in work.fulldata names stored in column called "ticker". have sorted data type (either etf or stock) cant figure out how select rows interested in these tables. thank you!
proc import out=work.fulldata datafile="/folders/myshortcuts/myfolder/q2_2012_all.csv" dbms=csv replace; getnames=yes; datarow=2; run; proc import out = work.etfnames datafile = "/folders/myshortcuts/myfolder/etfs.csv" dbms=csv replace; getnames=yes; datarow=2; run; proc sql; create table stocks select * fulldata security eq "stock"; quit; proc sql; create table etf select * fulldata security eq "etf" quit;
you might want try merging 2 datasets, , accepting have matching "ticker" values. i'm going assume dataset etfnames has names stored under variable "ticker" too.
proc import out= work.fulldata datafile= "/folders/myshortcuts/myfolder/q2_2012_all.csv" dbms=csv replace; getnames=yes; datarow=2; run; proc import out= work.etfnames datafile= "/folders/myshortcuts/myfolder/etfs.csv" dbms=csv replace; getnames=yes; datarow=2; run; proc sort data=work.fulldata out=work.fulldatasort; ticker; run; proc sort data=work.eftnames out=work.eftnamessort; ticker; run; data work.partdata; merge work.fulldatasort work.eftnamessort(in=a); ticker; if a; run; proc sql; create table stocks select * partdata security eq "stock"; quit; proc sql; create table etf select * partdata security eq "etf" quit;
as far can tell give desired result. join in proc sql statements instead of merge, merge easier write imo.
Comments
Post a Comment