How do I refer to a variable that might not be included in the varlist of a program?

I have simple program where I want to generate a variable t that es equal to the second argument. If there is no second argument I want t to be equal to the first argument:

Code:
cap prog drop try
prog try
    syntax varlist  
    gen t = `2'
    replace t=`1' if "`2'" == ""
end
when I invoke the program with
Code:
try var1 var2
it works all fine. If I try
Code:
try var1
I get invalid syntax.

I appreciate your help
Magnus