BookmarkSubscribeRSS Feed
yichentian226
Obsidian | Level 7

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. 

2 REPLIES 2
PaigeMiller
Diamond | Level 26

@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;
--
Paige Miller
yichentian226
Obsidian | Level 7

This is very helpful thank you 🙂

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 567 views
  • 1 like
  • 2 in conversation