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);

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 545 views
  • 2 likes
  • 4 in conversation