Use the COALESCE() function to select the first non-missing value from a list. Since your variable names have numeric suffixes you can use a variable list.
first = coalesce(of var1-var4);
Otherwise just list the variable names:
first = coalesce(of varA varB varC varD);
To find the last non-missing value just list the variables in the opposite order.
last = coalesce(of var4-var1);