Hi All, We want to assign Table Numbers for Demographics and Death Tables. But the merge is not working OutPut Pgm Hed DEM.RTF DEM Table_0 * two outputs DEM.LST DEM Table_0 * cannot be the same DOA.LST DOA Table_2 You want OutPut Pgm Hed DEM.RTF DEM Table_0 DEM.LST DEM Table_1 DOA.LST DOA Table_2 /* SAS Program names and output */ Data PgmOut(Label="OutPut and SAS Program Name"); input OutPut $ Pgm $ ; cards; DEM.RTF DEM DEM.LST DEM DOA.LST DOA ; run; /* Table Numbers to be applied to Program and Output */ Data PgmHed(Label="SAS Program and Heading for Output"); input Pgm $ Hed $10.; cards; DEM Table_1 DOA Table_2 ; run; /* The following merge does not work */ /* DEM.LST should be Table_1 not 'Table_0 */ /* SAS is Retaining our edited Heading from observation 1 */ /* we do not want two outputs with the same table numbers */ Data PgmWthHed(Label="Put Table numbers with output objects"); Merge PgmOut(In=OutObj) PgmHed ; by Pgm; If Scan(Output,2) = 'RTF' Then Hed='Table_0'; /* remove _ */ Run; options nocenter;run; proc print; run; /* Here is SQL code that fixes the problem */ proc sql; select r.OutPut, l.Pgm, case when(Scan(r.Output,2) = 'RTF') then 'Table_0' else l.Hed end as Hed from PgmHed as l, PgmOut as r where l.Pgm=r.Pgm order by l.Pgm ; quit;