02-07-2013 04:38 AM
Please please help. I have this really large dataset that I need to clean up so I need this process to be optimized the best way possible.
Please see below for sample records:
I need to search through all the data to see where num1 and num2 match and where cost = 0 and summarize the time accordingly in 1 record along with the class as per the above. I require the desired output.
Thanks for the help.
02-07-2013 05:43 AM
If data is already sorted (as in your example), it could be done in one step.
What about Class and ID, to you want the value from the last row of the ones that you want to condense?
Try to elaborate using BY, FIRST./LAST. and RETAIN.
02-07-2013 06:56 AM
Thanks for the response LinusH. Ok Ignore the question above. Let me rephrase.
Ideally I want to retain the last records class and ID where num1 and num2 are the same. My condition will be if num1 and num2 are the same and cost = 0 than take the last record.
02-07-2013 10:01 AM
Thanks for your help.
Is this way the best way to select the last record for a dataset were num1 and num2 are the same?? Also cost will have to be 0.
My data set has 80612210 obs. I dont want this process to take too long as I have quite a few data steps after this one.
02-07-2013 04:26 PM
You need to have the data sorted in the order you want it, and exclude the data you don't want. If your data is already sorted, put the where clause on the set statement. To save time/space, only keep the variables you need. (I'm not sure if you need to keep seq after the data is sorted, for example.)
proc sort data=have(keep=num1 num2 seq class cost time ID where=(cost=0)) out=haveSorted(drop=cost seq);
by num1 num2 seq;
by num1 num2;
if last.num2 then output;
02-07-2013 09:35 AM
Not very sure if this is what you are after, but it seems to have the expected output for your as-is incoming data:
input SEQ Num1 Num2 Class:$1. Cost Time ID :$4.;
1 12 13 . 0 50 A123
2 12 13 A 0 60 A123
3 12 18 A 60 10 A123
/*if pre-sorted by num1 num2*/
by num1 num2;
if first.num2*last.num2=1 then output;
else if last.num2 and cost=0 then output;
Need further help from the community? Please ask a new question.