BookmarkSubscribeRSS Feed
Barney1998
Obsidian | Level 7

Hallo to everyone.

I have this problem. I have a big data set so this i will try to explain you it was difficult to be implemented by hand.

 

First of all i have one data set which looks like:

qq1 qq2 qq3 qq4
1                              
          0     

          0 
                 2          
                       11
i want to pick up all the variables in one new column 
like
qq
1
0
0
2
11

from the first table if one column value is not missing means that all the other columns are missing in the same row
thank you in advance

               

1 REPLY 1
FreelanceReinh
Jade | Level 19

Hallo @Barney1998,

 

If qq1 - qq4 are numeric variables, you can use the COALESCE function to obtain the first non-missing value:

data have;
input qq1-qq4;
cards;
1 . . .
. 0 . .
. 0 . .
. . 2 .
. . . 11
;

data want(drop=qq1-qq4);
set have;
qq=coalesce(of qq1-qq4);
run;

 

For character variables there is the similar COALESCEC function.

 

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 643 views
  • 3 likes
  • 2 in conversation