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

Dear programmers,

 

I have a dataset like this:

 

ID COLUMN_A COLUMN_B
1001 1 .
1002 2 .
1003 3 .
1004 4 .
1005 5 .
1006 6 6
1007 7 7
1008 . 8
1009 . 9
1010 . 10
1010 . 11
1011 . 12
1012 . 13

 

I want to merge COLMN_A and COLMN_B into a new column (COLUMN_C) to overwrite the missing values:

 

ID COLUMN_C
1001 1
1002 2
1003 3
1004 4
1005 5
1006 6
1007 7
1008 8
1009 9
1010 10
1010 11
1011 12
1012 13

 

How can I do it without getting duplicates?

 

Best regards

 

Farshid 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Like this?

 

What do you mean by 'without duplicates'?

 

data have;
input ID COLUMN_A COLUMN_B;
datalines;
1001 1 .
1002 2 .
1003 3 .
1004 4 .
1005 5 .
1006 6 6
1007 7 7
1008 . 8
1009 . 9
1010 . 10
1010 . 11
1011 . 12
1012 . 13
;

data want(keep=ID COLUMN_C);
    set have;
    COLUMN_C=coalesce(of col:);
run;

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Like this?

 

What do you mean by 'without duplicates'?

 

data have;
input ID COLUMN_A COLUMN_B;
datalines;
1001 1 .
1002 2 .
1003 3 .
1004 4 .
1005 5 .
1006 6 6
1007 7 7
1008 . 8
1009 . 9
1010 . 10
1010 . 11
1011 . 12
1012 . 13
;

data want(keep=ID COLUMN_C);
    set have;
    COLUMN_C=coalesce(of col:);
run;
PaigeMiller
Diamond | Level 26

Hello @farshidowrang 

 

Is your example representative of all possible data in the data set, where either column_A equals column_B OR (one of column_A and column_B is missing)? Can column_A equal 8 and column_B equal 9 on the same row?

--
Paige Miller
farshidowrang
Quartz | Level 8

Good question

 

Thank you

 

The answer is I don't know it right now

 

Best regards

 

Farshid 

rudfaden
Lapis Lazuli | Level 10

you could try update.

 

data Master;
input ID $ Value;
datalines;
1 1
2 2
2 2
3 3
4 4
5 5
;
 
data Trans;
input ID $ Value;
datalines;
1 10
2 20
4 10
4 20
4 30
5 6
6 60
;
 
data want;
   update Master Trans updatemode=missingcheck;
   by ID;
run;
farshidowrang
Quartz | Level 8

nice code

 

Thank you very much!

I have tried it

 

It's a useful code

 

Thanx 

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 5 replies
  • 2107 views
  • 3 likes
  • 4 in conversation