merge files like VLOOKUP

I would like to merge data from a reference file and a data file to produce a new output file as shown below.
Reference file,data file,output file
a , b 2 , a 0
b , d 4 , b 2
c , , c 0
d , , d 4
e, , e 0

$ cat dat
b 2
d 4
$ cat ref
a
b
c
d
e
$ awk '{F+=(FNR==1)
>   if (F==1) val[$1]=$2
>   if (F==2) print $1, val[$1] ? val[$1] : 0}' dat ref
a 0
b 2
c 0
d 4
e 0

Thankyou very much. It worked well!

awk 'NR==FNR{a[$1]=$2;next} {print $1,a[$1]?a[$1]:0}' dat ref