Hello,
There are two datasets, lets say dataset abc and dataset def
First I am trying to create a new string variable named: openflag in dataset abc, and the value to be 1 for the records. Can anyone check if my steps are right?
data abc;
set abc;
openflag = 1;
run;
Second I want to right join dataset abc with dataset def (keep all the records from def and those matching values from abc), let's say the new dataset after join steps is NEW. Now I have openflag in NEW, I wonder how to replace the missing values into 0? Thanks very much.
@yichentian226 wrote:
Hello,
There are two datasets, lets say dataset abc and dataset def
First I am trying to create a new string variable named: openflag in dataset abc, and the value to be 1 for the records. Can anyone check if my steps are right?
data abc;
set abc;
openflag = 1;
run;
You can check this yourself. Just run the code and see if you get the desired results.
Second I want to right join dataset abc with dataset def (keep all the records from def and those matching values from abc), let's say the new dataset after join steps is NEW. Now I have openflag in NEW, I wonder how to replace the missing values into 0?
Are you referring to missing values because the join found no records in the left data set? Then something like this
proc sql;
create table new as select *.
case when missing(abc.openflag) then 0 else abc.openflag as openflag1
from abc right join def on
/* you have to specify the ON condition as your text didn't really mention what it was */
abc.something=def.something;
quit;
This is very helpful thank you 🙂
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.