10-09-2013 09:42 AM
IF last.Customer_key then output;
10-09-2013 10:22 AM
It outputs to dataset Mart.Fica_Lock_up the LAST sorted observation of every by group (in this case by-groups of the variable customer_key).
It might be helpful if your title line spoke about the actual problem you have instead of how the problem is identified in the text (example: What does "if last.customer_key" do)
10-09-2013 10:27 AM
First. and Last. are fairly well explained in SAS documentation. You may want to search and read it for yourself. In the mean time, here's my quick explanation:
When you use BY group processing (statement by customer_key, SAS creates 2 additionnal automatic variables per by variable to help you process your groups.
Assume the following statement:
by var1 var2 var3;
then SAS creates
automatic variables. They are binary (0 or 1) variables that indicate whether the current record is the first (Resp. last) in the current group.
Since FALSE=0 and TRUE=1, the statement IF last.customer_key then output; is equivalent logically to IF last.customer_key=TRUE then output;
That is, the above statement controls your output and only outputs the last record for each distinct customer_key in query_for_cust_e_0002 to mart.fica_lock_up
Imagine the following data set that you read with a BY var1 var2 var3; statement:
rownum var1 var2 var3
1 1 1 1
2 1 2 1
3 1 2 2
4 1 2 3
5 1 3 1
In the Above, first.var1 = 1 only for rownum=1. Last.var1=1 only for rownum=5
first.var2=1 for each rownum in (1, 2, 5) and last.var2=1 for each rownum in (1, 4, 5)
first.var3=1 for each rownum in (1,2,3,4,5) and last.var3=1 for each rownum in (1,2,3,4,5)
Thus, the first and last automatic variables created allow you, for example, to reset counters, reset sums to 0 or products to 1 for your desired by group. They also allow you control over time series where you are only interested in values at the begining and end of a by group, etc.
Hope this helps.