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
;

 

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