Join fields comparing 4 fields using awk

Hi All,

I am looking for an awk script to do the following
Join the fields together only if the first 4 fields are same.
Can it be done with join function in awk??

 a,b,c,d,8,,,
a,b,c,d,,7,,
a,b,c,d,,,9,
a,b,p,e,8,,,
a.b,p,e,,9,,
a,b,p,z,,,,9
a,b,p,z,,8,,

desired output:

 a,b,c,d,8,7,9,
a,b,p,e,8,9,,
a,b,p,z,,8,,9

Thanks.

Not sure that this is the most efficient / intelligent solution, but you can use it as a hint to be improved:

awk -F, '{X=sprintf("%s,%s,%s,%s",$1,$2,$3,$4)
          A5[X]=A5[X]?A5[X]:$5
          A6[X]=A6[X]?A6[X]:$6
          A7[X]=A7[X]?A7[X]:$7
          A8[X]=A8[X]?A8[X]:$8
        }
         END {for (i in A5) print i, A5, A6, A7, A8}
        ' OFS="," file
a,b,p,e,8,9,,
a,b,p,z,,8,,9
a,b,c,d,8,7,9,

A bit more care when preparing the sample hadn't hurt, had it?