SAS: Compare values between two numbers to make separate buckets -
i'm trying compare multiple sets of data putting them in separate groups between 2 numbers. had statements like,
if column1 gt 0 , column1 le 1000 price_group = 1000;
i had going 1000 100,000. problem once counted how many in each price_group, price_groups missing (57,000 had no values when count(price_group) not appear groups). solution think make table bounds each, , compare actual value vs upper , lower bound.
proc iml; mat = j(100,2,0); total = 100000; mat[1,1] = 0; mat[1,2] = mat[1,1] + (total/100); = 2 nrow(mat); mat[i,1] = mat[i-1,1] + (total/100); mat[i,2] = mat[i,1] + (total/100); end; create dataset mat; append mat; quit;
this creates table can compare values, there easier way besides proc iml? next going loop compare each value 2 columns , create new column on table have count in each bucket. still seems intensive process inefficient.
iml isn't terrible solution, there few others depending on you're doing.
the common proc format
. create format manages each bucket, so:
proc format; value buckets 0-1000 = 1000 1000<-2000 = 2000 ... other="na"; quit;
then can either use format (or informat) create new variable bucketed value, or better, use format on fly (ie, in proc means or whatnot) not means don't have rewrite dataset, can swap formats on , off depending on how many buckets want (say, buckets100
format or buckets20
, whatnot).
second, specific question looks it's solveable using math:
data want; set have; bucket = &total/100*(1+floor(column1/(&total/100))); run;
although doesn't work every example.
third, use hash lookup table, if unable use formats (such there 2 or more elements determine bucket). if that's useful can expand on that, or google commonly used lookups in sas. that's closest solution iml solution inside regular datastep.
Comments
Post a Comment