sas - Loop through list -


i have following macro:

rsubmit;   data indexsecid; input secid 1-6; datalines; 108105 109764 102456 102480 101499 102434 107880 run; %let endyear = 2014;  %macro getvols1;   * first extract secids options given date ,   expiry date;   %do yearnum = 1996 %to &endyear;   proc sql;         create table volsurface1&yearnum         select a.secid, a.date, a.days, a.delta, a.impl_volatility,         a.impl_strike, a.cp_flag         optionm.vsurfd&yearnum a, indexsecid b         a.secid=b          , a.impl_strike ne -99.99         order a.date, a.secid, a.impl_strike;   quit; %if &yearnum > 1996 %then %do; proc append base= volsurface11996 data=volsurface1&yearnum; run; %end; %end;    %mend; %getvols1;   proc download data=volsurface11996; run;     endrsubmit;  data _null_; set work.volsurface11996; length fv $ 200; fv = "c:\users\user\desktop\" || trim(put(indexsecid,4.)) || ".csv"; file write filevar=fv dsd dlm=',' lrecl=32000 ; put (_all_) (:); run; 

on code above have: a.secid=108105. have list several secid , need run macro once each secid. looking run once , generate new dataset each secid. how can that? thanks

here approach uses


%let startyear = 1996; %let endyear = 2014;  data volsurface1;   /* read in input tables */   set optionm.vsurfd&startyear.-optionm.vsurfd&endyear.;   impl_strike ~= -99.99;   /* set hash table containing wanted secids */   if _n_ = 1 do;     declare hash h(dataset: "indexsecid");     _rc = h.definekey("secid");     _rc = h.definedone();   end;   /* keep observations secid matched in hash table */   if not h.find();   /* select variables output */   keep secid date days delta impl_volatility impl_strike cp_flag; run;  /* sort data */ proc sort data = volsurface1;   secid date secid impl_strike; run;  /* write out csv each secid */ data _null_;   set volsurface1;   length fv $200;   fv = "\path\to\output\" || trim(put(secid, 6.)) || ".csv";   file write filevar = fv dsd dlm = ',' lrecl = 32000;   put (_all_) (:); run; 

as don't have data untested. constraint can see contents of indexsecid must fit in memory. if not concerned order done in 1 data step.


Comments

Popular posts from this blog

tcpdump - How to check if server received packet (acknowledged) -