macros - Subset based on criteria in sas -


let's hope have worded question correctly.

i have pulled series of cricketing scorecards , have 'x' scorecards (datasets) each containing 'n' rows of observations. want create 'k' subsets 'x' scorecards automatically dividing each scorecard dataset 8. (for e.g. 1 of scorecards has 168 observations therefore scorecard broken 21 subsets, while scorecard contains 128 entries broken 16 subsets).

i want transpose each of 'k' subsets, give me dataset containing 1 row. want stack 'k' transposed datasets create 1 big dataset.

small example:

nt broom b henry 21 12 15 3 1 140 jd ryder b henry 1 3 2 0 0 50.00 

(small extract 1 of scorecards) above dataset divided 2 subsets, each of 2 subsets transposed produce below (2) datasets:

  1. nt broom b henry 21 12 15 3 1 140.00
  2. jd ryder b henry 1 3 2 0 0 50.00

the 2 datasets stacked on top of each:

nt broom b henry 21 12 15 3 1 140.00

jd ryder b henry 1 3 2 0 0 50.00

hope makes sense.

thanks in advance, ankit

what i've done far:

/batting subset macro/

proc sql;      select count (8) into:total compile_bat_cleaned_&match;  quit;   %macro create_subsets(count,compile_bat_cleaned_665647);     %let cnt = %sysfunc(ceil(%sysevalf(&count/8)));     %let num = 1;      %do = 1 %to &cnt;         %if(&i = &cnt) %then %do;             %let toread = &count;         %end;         %else %do;             %let toread = &num + 7;          %end;     data compile_bat_cleaned_665647_&i;      set compile_bat_cleaned_665647 (firstobs=&num obs=%eval(&toread));     run;    proc transpose data = compile_bat_cleaned_665647_&i out = compile_bat_cleaned_665647_&i (drop=_name_);             var bat_det_2_term details_4;     data compile_bat_cleaned_665647_&i;       set compile_bat_cleaned_665647_&i (firstobs = 2);    rename col1 = batsman           col2 = dismissal           col3 = runs_scored           col4 = minutes           col5 = balls           col6 = fours           col7 = sixes           col8 = strike_rate;     %let num = %eval(&num + 8);   %end;  data batters_merged_665647;   set    %do = 1 %to &cnt;     compile_bat_cleaned_665647_&i   %end;   ; run;  %mend create_subsets;  %create_subsets(&total,compile_bat_cleaned_665647); 

the above piece of code works individual scorecards (match=665647), not series of scorecard data. change macro %macro create_subsets(count,compile_bat_cleaned_&match) doesn't seem work

the thing you're missing by group processing. things in sas don't have split 1 dataset per id or that; assign id variable , whatever by variable.

in case, if have variable playerid has 1 first 8 rows, 2 second 8 rows (9-16), etc., can proc transpose by playerid;, , 1 transpose, 1 dataset single dataset. no macro, no fuss.


Popular posts from this blog