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

Hello I have this data with four variables A, B, C D that I want to make it one variable A. THe data is as such.

A              B             C           D

1               1             1            .

2              1             .             1

.               2             1            .

.                .             2            .

.                .              .           3

 

I want to create this data with one variable call A as above

F

1

2

2

3

 

The variable A B C D are in order and F takes the first number. If  all are missing, F will be missing otherwise F takes the first value from the variable A, B, C, D.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

The coalesce() function will pick the first non-missing value.

data sample;
  input A B C D;
  F=coalesce(a,b,c,d);
datalines;
1 1 1 .
2 1 . 1
. 2 1 .
. . 2 .
. . . 3
;

 

View solution in original post

2 REPLIES 2
desireatem
Pyrite | Level 9

Actually F is: F

F

1

2

2

2

3

 

Patrick
Opal | Level 21

The coalesce() function will pick the first non-missing value.

data sample;
  input A B C D;
  F=coalesce(a,b,c,d);
datalines;
1 1 1 .
2 1 . 1
. 2 1 .
. . 2 .
. . . 3
;

 

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
  • 903 views
  • 1 like
  • 2 in conversation