Q:

Join two variables by colum and fill the blank row with default value

I want to join two variables by column by column also filling the blank row with some default value. 
echo var1
location|Serial
001|0
003|1
007|0
009|1

echo var2
name|location|type|built
name1|001|type1|2009
name2|003|type4|2012
name3|007|type1|2010
name4|009|type2|2015
name5|002|type0|2016

I managed to print following:
 paste <(echo "$var2"|awk 'BEGIN{print "name","location","type","built","serial"} NR>1') <(echo "$var1"|awk -F'|' 'NR>1{$1=$1;print FS $2}')
name location type built serial |0
name1|001|type1|2009    |1
name2|003|type4|2012    |0
name3|007|type1|2010    |1
name4|009|type2|2015
name5|002|type0|2016

desired output:
name|location|type|built|serial
name1|001|type1|2009|0
name2|003|type4|2012|1
name3|007|type1|2010|0
name4|009|type2|2015|1
name5|002|type0|2016|NA

A:

Try this - 
 awk 'BEGIN{FS=OFS="|"} NR==FNR{a[$1]=$2;next} {print (a[$2]!=""?$0 OFS a[$2] : $0 OFS "NA")}' <(echo "$var1") <(echo "$var2")
name|location|type|built|Serial
name1|001|type1|2009|0
name2|003|type4|2012|1
name3|007|type1|2010|0
name4|009|type2|2015|1
name5|002|type0|2016|NA

Explained - 
print (a[$2]!=""?$0 OFS a[$2] : $0 OFS "NA" Working as left outer
  join, if Value is not found for 5th column it will get replaced with 
  "NA"

A:

awk 'BEGIN{ 
            FS=OFS="|"                         # set i/p and o/p field separator
     }
     FNR==NR{                                  # Here we read contents from first arg
               a[$1]=$2;                       # populate array a where index being field1 and value being field2
               next                            # stop processing go to next line
     }
     {                                         # Here we read second arg
        print $0,($2 in a) ? a[$2] : "NA"      # if array a has index that is field2 value of 2nd file/var then serial no else NA 
     }' <(echo "$var1") <(echo "$var2")

Since your input is variable not file, so you can do something like below
Define variables
$ read -d -r var1 <<EOF                                                             
location|Serial
001|0
003|1
007|0
009|1
EOF

$ read -d -r var2 <<EOF 
name|location|type|built
name1|001|type1|2009
name2|003|type4|2012
name3|007|type1|2010
name4|009|type2|2015
name5|002|type0|2016
EOF  

Contents of variable
$ echo "$var1"
location|Serial
001|0
003|1
007|0
009|1

$ echo "$var2"
name|location|type|built
name1|001|type1|2009
name2|003|type4|2012
name3|007|type1|2010
name4|009|type2|2015
name5|002|type0|2016

Output
$ awk 'BEGIN{FS=OFS="|"}FNR==NR{a[$1]=$2;next}{print $0,($2 in a)?a[$2]:"NA"}' <(echo "$var1") <(echo "$var2")
name|location|type|built|Serial
name1|001|type1|2009|0
name2|003|type4|2012|1
name3|007|type1|2010|0
name4|009|type2|2015|1
name5|002|type0|2016|NA

Read built-in

-d DELIM The first character of DELIM is used to terminate the input
  line, rather than newline.
-r  If this option is given, backslash does not act as an escape
  character. The backslash is considered to be part of the line. In
  particular, a backslash-newline pair may not be used as a line
  continuation.

