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
select
c2.*
,ca3.cartel_byear
,ca3.cartel_eyear
,case
when ca3.cartel_byear=<cyear<=ca3.cartel_eyear then 1
else 0
end as cartel_year
from c2 left join ca3
on c2.gvkey=ca3.gvkey
;
quit;
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
... View more