Hi:
A good technique for diagnosing issues like the one you experienced is to use the PUT or PUTLOG statement to write selected variables from the Progarm Data Vector (PDV) as a debugging technique. For example, the log below shows the result of using PUTLOG statements to see what was happening in your program with the DOB and AGE variables:
[pre]
1671 ** diagnose initialization issues with 2 set statements;
1672 ** and see how using IN= might help;
1673 data diagnose;
1674 set data1(in=inone) data2(in=intwo);
1675 putlog '***';
1676 putlog '***** After SET';
1677 put _n_ inone= intwo= name= dob= age= person_dob= person_age= xdob= xage=;
1678
1679 if dob=. then dob=input(put(person_dob,8.),yymmdd8.);
1680 if age=. then age=input(person_age,8.);
1681
1682 *** make OTHER variables not in either dataset;
1683 *** XDOB and XAGE will ONLY be created when an obs comes;
1684 *** from DATA2 dataset.;
1685 if intwo then do;
1686 xdob=input(put(person_dob,8.),yymmdd8.);
1687 xage=input(person_age,8.);
1688 end;
1689
1690 putlog '***** After IF for DOB and AGE';
1691 put _n_ inone= intwo= name= dob= age= person_dob= person_age= xdob= xage=;
1692 run;
***
***** After SET
1 inone=1 intwo=0 name=John Smith dob=9490 age=25 person_dob=. person_age= xdob=. xage=.
***** After IF for DOB and AGE
1 inone=1 intwo=0 name=John Smith dob=9490 age=25 person_dob=. person_age= xdob=. xage=.
***
***** After SET
2 inone=1 intwo=0 name=Jack Bauer dob=185 age=50 person_dob=. person_age= xdob=. xage=.
***** After IF for DOB and AGE
2 inone=1 intwo=0 name=Jack Bauer dob=185 age=50 person_dob=. person_age= xdob=. xage=.
***
***** After SET
3 inone=1 intwo=0 name=Charlie Day dob=7233 age=31 person_dob=. person_age= xdob=. xage=.
***** After IF for DOB and AGE
3 inone=1 intwo=0 name=Charlie Day dob=7233 age=31 person_dob=. person_age= xdob=. xage=.
***
***** After SET
4 inone=0 intwo=1 name=Patrick Stewart dob=. age=. person_dob=19500406 person_age=60 xdob=. xage=.
***** After IF for DOB and AGE
4 inone=0 intwo=1 name=Patrick Stewart dob=-3557 age=60 person_dob=19500406 person_age=60 xdob=-3557 xage=60
***
***** After SET
5 inone=0 intwo=1 name=Steve Jobs dob=-3557 age=60 person_dob=19520115 person_age=58 xdob=. xage=.
***** After IF for DOB and AGE
5 inone=0 intwo=1 name=Steve Jobs dob=-3557 age=60 person_dob=19520115 person_age=58 xdob=-2908 xage=58
***
***** After SET
6 inone=0 intwo=1 name=Bill Gates dob=-3557 age=60 person_dob=19510803 person_age=59 xdob=. xage=.
***** After IF for DOB and AGE
6 inone=0 intwo=1 name=Bill Gates dob=-3557 age=60 person_dob=19510803 person_age=59 xdob=-3073 xage=59
NOTE: There were 3 observations read from the data set WORK.DATA1.
NOTE: There were 3 observations read from the data set WORK.DATA2.
NOTE: The data set WORK.DIAGNOSE has 6 observations and 7 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
[/pre]
In addition to creating XDOB and XAGE so you could see the difference in initialization for those two variables versus the way you did it (by reusing existing variables that came from DATA1, I also show the use of the IN= data set option so you might check it out as a different way to do your test. Finally, I have a simpler suggestion for how to do the creation of the variables where you need to do the conversion for DATA2 obs (shown in the program below). Also, I showed the use of the INPUT function with the PUT function to get rid of "automatic conversion" messages in the SAS log.
Alternate suggestion:
[pre]
data simpler;
set data1(in=inone) data2(in=intwo);
** only create dob and age for observations from DATA2;
** you avoid the issue of testing for missing dob and age because;
** you know that variables from DATA2 will ONLY fall into the IF condition.;
if intwo then do;
dob=input(put(person_dob,8.),yymmdd8.);
age=input(person_age,8.);
end;
*drop person_age person_dob;
run;
proc print data=simpler;
format dob yymmdd10.;
run;
[/pre]
cynthia