Hi ,
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.
Code:
proc sql;
create table QHPNOTEPtable_1 as
select Q.*,M.market_name from QHPNOTEPtable Q
left join table1 M ON Q.grPnum= M.group_ID;
quit;
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;
Post some data to let us test it . and post the output you want to see.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.