loops - SAS: Creating multiple datasets at once from an excel file -


i have excel file 500 stock tickers. wish extract big sas dataset each stock's returns , additional observations. before, 20 stock tickers, follow:

data s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13 s14 s15 s16 s17 s18 s19 s20;  set tick; if stock='dis' output s1; if stock='aa' output s2;  if stock='qcom' output s3;  if stock='fb' output s4;  if stock='amgn' output s5; if stock='amzn' output s6;  if stock='axp' output s7;  if stock='nws' output s8;  if stock='intc' output s9;  if stock='krft' output s10; if stock='cb' output s11;  if stock='celg' output s12;  if stock='cmcsa' output s13;  if stock='cost'  output s14;  if stock='csco' output s15; if stock='yhoo' output s16;  if stock='dell' output s17;  if stock='vod' output s18;  if stock='dow' output s19;  if stock='ebay' output s20; run; 

where tick sas dataset contains entire population of stock returns.

then each s1, s2....s20 use loop iterate among 20 different files , apply additional sas code.

i want avoid filling sas code 500 lines of e.g. if stock='cost' output s14; if need apply series of sas code on each ticker.

is there way me have sas loop goes through each line of excel file, selects first ticker, creates sas dataset s1 apply sas code s1 file , once done, go top of loop, select second line of excel (hence second ticker) , repeat process?

first, better off leaving things in 1 data set , using groups down stream processing.

if must, can script macro this:

%macro split(); proc sql noprint; select count(distinct stock)     :n     tick;  select distinct stock     :s1 - :s%left(&n)     tick; quit;  data     %do i=1 %to &n;     s&i     %end; ; set tick;  %do i=1 %to &n;    if stock = "&&s&i" output s&i; %end; run; %mend;  %split(); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -