BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ahassanin777
Calcite | Level 5

As part of a large data set, 2 of my columns need to be combined with observations (from column A) replacing blanks (in column B), while at the same time having all observations from column B stay in the final output. To clarify further all observations from column A with the value "9" (only this value) need to be replaced by whatever is in Column B in the final output.  

 

Here is an example data:

 

 

 

ID  Column A      Column B     Desired output    

A1     1                         .                1

A2     3                         .                3

A3     4                          .               4 

A4     9                        7                7

A5     9                        7                7

A6     4                        .                 4

A7     6                        .                 6

A8     1                        .                 1

A9     9                        8                8

 

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi are you asking for an if then?

 

 

data want;

set have;
colb=coalesce(colb,col_a);
desired=ifn(col_a=9,colb,col_a);

run;

 

 

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

Hi are you asking for an if then?

 

 

data want;

set have;
colb=coalesce(colb,col_a);
desired=ifn(col_a=9,colb,col_a);

run;

 

 

ahassanin777
Calcite | Level 5

It worked. Thank you very much!

Patrick
Opal | Level 21
data sample;
  infile datalines dlm=' ' dsd;
  input ID $ Column_A Column_B Desired_output;
  want=ifn(Column_A=9,Column_B,Column_A);
  datalines;
A1 1 . 1
A2 3 . 3
A3 4 . 4 
A4 9 7 7
A5 9 7 7
A6 4 . 4
A7 6 . 6
A8 1 . 1
A9 9 8 8
;
run;
Tom
Super User Tom
Super User

Perhaps your test data does not show the actual complexity?

Looks like you just want to use the COALESCE() function.

want  = coalesce(B,A);

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 4 replies
  • 1056 views
  • 2 likes
  • 4 in conversation