<P>You have two ways to do it: </P>
<P>1. Use 'case' function to create a new variable, 'case' is really similar like 'if ... then' in your datastep.</P>
<P>2. Use 'coalesce' with OUTER JOINS (full join, left join, right join) operations: </P>
<P>coalesce (a.id, 0) will change all missing values or unmatched values of a.id as 0.</P>
<P>coalesce (b.id, 9999) will change all unmatched or missing value of b.id as 9999.</P>
<P><B><FONT face="Courier New" color=#000080 size=2>data</B></FONT><FONT face="Courier New" size=2> a;</P></FONT><FONT face="Courier New" color=#0000ff size=2>
<P>input</FONT><FONT face="Courier New" size=2> id age;</P></FONT><FONT face="Courier New" color=#0000ff size=2>
<P>cards</FONT><FONT face="Courier New" size=2>;</P>
<P>3 12</P>
<P>4 5</P>
<P>5 35</P>
<P>6 20</P>
<P>7 11</P>
<P>8 20</P>
<P>;</P></FONT><B><FONT face="Courier New" color=#000080 size=2>
<P>run</B></FONT><FONT face="Courier New" size=2>; </P></FONT><B><FONT face="Courier New" color=#000080 size=2>
<P>data</B></FONT><FONT face="Courier New" size=2> b;</P></FONT><FONT face="Courier New" color=#0000ff size=2>
<P>input</FONT><FONT face="Courier New" size=2> id gender $;</P></FONT><FONT face="Courier New" color=#0000ff size=2>
<P>cards</FONT><FONT face="Courier New" size=2>;</P>
<P>1 F</P>
<P>2 M</P>
<P>4 M</P>
<P>6 F</P>
<P>7 M</P>
<P>10 F</P>
<P>11 M</P>
<P>;</P></FONT><B><FONT face="Courier New" color=#000080 size=2>
<P>run</B></FONT><FONT face="Courier New" size=2>;</FONT></P>
<P><FONT face="Courier New" size=2>***METHOD 1****;<B><FONT face="Courier New" color=#000080 size=2></P>
<P>proc</B></FONT><FONT face="Courier New" size=2> </FONT><B><FONT face="Courier New" color=#000080 size=2>sql</B></FONT><FONT face="Courier New" size=2>;</P></FONT><FONT face="Courier New" color=#0000ff size=2>
<P>select</FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#008080 size=2>a.</FONT><FONT face="Courier New" size=2>*, b.gender, </P>
<P></FONT><FONT face="Courier New" color=#0000ff size=2>case</FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#0000ff size=2>when</FONT><FONT face="Courier New" size=2> a.id></FONT><B><FONT face="Courier New" color=#008080 size=2>0</B></FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#0000ff size=2>then</FONT><FONT face="Courier New" size=2> </FONT><B><FONT face="Courier New" color=#008080 size=2>1</B></FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#0000ff size=2>else</FONT><FONT face="Courier New" size=2> </FONT><B><FONT face="Courier New" color=#008080 size=2>0</B></FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#0000ff size=2>end</FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#0000ff size=2>as</FONT><FONT face="Courier New" size=2> ina,</P>
<P></FONT><FONT face="Courier New" color=#0000ff size=2>case</FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#0000ff size=2>when</FONT><FONT face="Courier New" size=2> b.id></FONT><B><FONT face="Courier New" color=#008080 size=2>0</B></FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#0000ff size=2>then</FONT><FONT face="Courier New" size=2> </FONT><B><FONT face="Courier New" color=#008080 size=2>1</B></FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#0000ff size=2>else</FONT><FONT face="Courier New" size=2> </FONT><B><FONT face="Courier New" color=#008080 size=2>0</B></FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#0000ff size=2>end</FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#0000ff size=2>as</FONT><FONT face="Courier New" size=2> inb</P></FONT><FONT face="Courier New" color=#0000ff size=2>
<P>from</FONT><FONT face="Courier New" size=2> a full join b</P>
<P>on a.id=b.id;</P></FONT><B><FONT face="Courier New" color=#000080 size=2>
<P>quit</B></FONT><FONT face="Courier New" size=2>;</FONT></P>
<P>***MATHOD 2****;</FONT><FONT face="Courier New" size=2></P></FONT><B><FONT face="Courier New" color=#000080 size=2>
<P>proc</B></FONT><FONT face="Courier New" size=2> </FONT><B><FONT face="Courier New" color=#000080 size=2>sql</B></FONT><FONT face="Courier New" size=2>;</P></FONT><FONT face="Courier New" color=#0000ff size=2>
<P>select</FONT><FONT face="Courier New" size=2> </FONT><FONT face="Courier New" color=#008080 size=2>a.</FONT><FONT face="Courier New" size=2>*, b.gender, coalesce(a.id, </FONT><B><FONT face="Courier New" color=#008080 size=2>0</B></FONT><FONT face="Courier New" size=2>) </FONT><FONT face="Courier New" color=#0000ff size=2>as</FONT><FONT face="Courier New" size=2> ina, coalesce (b.id,9999</FONT><FONT face="Courier New" size=2>) </FONT><FONT face="Courier New" color=#0000ff size=2>as</FONT><FONT face="Courier New" size=2> inb</P></FONT><FONT face="Courier New" color=#0000ff size=2>
<P>from</FONT><FONT face="Courier New" size=2> a full join b</P>
<P>on a.id=b.id;</P></FONT><B><FONT face="Courier New" color=#000080 size=2>
<P>quit</B></FONT><FONT face="Courier New" size=2>;</P></FONT>
[此贴子已经被作者于2007-2-23 5:33:31编辑过]