!if x = y
is actually a number test, you need to use ==
to test strings.
You need to trick the compiler to get this to work:
; NSIS 2+
!define DOLLAR $
!if "$%foo%" == "${DOLLAR}%foo%"
!echo "%foo% not set"
!endif
; NSIS 3+
!if "$%foo%" == "${U+24}%foo%"
!echo "%foo% not set"
!endif