BookmarkSubscribeRSS Feed
Babloo
Rhodochrosite | Level 12

I've a dataset like below.

 

A    B

1    .

.     2

3    .

.     4

5    .

 

I need the dataset like below. Basically I need the non-missing values for each observation. May I request someone to guide me to accomplish this task via Proc SQL?

 

A    B   C

1    .     1

.     2    2

3    .     3

.     4    4

5    .     5

2 REPLIES 2
sbxkoenk
SAS Super FREQ

Like this.

 

The MAX function ignores null values and SAS missing values. So the missing is completely ignored. Thus: max does not return 5 because 5 > . , the missing is just not considered.

 

data ab;
input a b;
datalines;
1    .
.    2
3    .
.    4
5    .
;
run;

PROC SQL noprint;
 create table abc as
 select * , max(a,b) as c  
 from ab;
QUIT;
/* end of program */

 

 

Koen

Reeza
Super User
I would recommend the coalesce() function which takes the first non missing value in a series of variables specified.

Coalesce(a, b) as C

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 763 views
  • 1 like
  • 3 in conversation