I would like to add conditions when two datasets are merged.
That is, how can we add conditions 'when cartel_byear=<cyear<=cartel_eyear then cartel_year=1; else cartel_year=0' when c2 (firm-year population) and ca3 are merged.
proc sql undo_policy=none; create table c3 as select c2.*,ca3.cartel_byear, ca3.cartel_eyear from c2 left join ca3 on when cartel_byear=<cyear<=cartel_eyear then cartel_year=1; else cartel_year=0; (c2.gvkey=ca3.gvkey) ; quit;
If you want us to provide tested code then please provide your sample data in the form of a working SAS data step. Take the discussion here as an example how to provide such information.
If I understand right then you want to create a new variable with a value populated on some condition. That would be done in the SELECT statement via a CASE expression. Docu for CASE is here.
Below code not tested.
proc sql undo_policy=none;
create table c3 as
when ca3.cartel_byear=<cyear<=ca3.cartel_eyear then 1
end as cartel_year
from c2 left join ca3
From the data provided it was unclear to me from which source table cyear is coming. You will eventually have to add the table alias to it for things to work. If the variable only exists in one of the tables then things will also work without that alias - but it's cleaner to always add it. ca3.cartel_byear=<cyear<=ca3.cartel_eyear
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.