08-25-2016 04:13 PM
We have a table1 which contains marketname ,year fields that has the data from the year 2014 to 2016.
Currently we are pulling data from table1 for the year 2016. While we join with this table 1 to get marketname for 2016 and its not matching. But if there is no matching, please match by previous year names table, if still not, use previous previous year
For example, if 2016 name not match, then use 2015, if still not, use 2014.
Please let me know how to go back for previous years and get the names.
create table QHPNOTEPtable_1 as
select Q.*,M.market_name from QHPNOTEPtable Q
left join table1 M ON Q.grPnum= M.group_ID;
08-25-2016 04:38 PM
Try to build something like this:
proc sql; create table QHPNOTEPtable_1 as select Q.*, coalesce(M0.market_name, M1.market_name, M2.market_name) as market_name from QHPNOTEPtable as Q left join table1 as M0 on Q.grPnum= M0.group_ID left join table1 as M1 on Q.grPnum= M1.group_ID left join table1 as M2 on Q.grPnum= M2.group_ID where M0.year=2016 and M1.year=2015 and M2.year=2014; quit;