Desktop productivity for business analysts and programmers

How do I combine multiple numeric columns into one?

Reply
Established User
Posts: 1

How do I combine multiple numeric columns into one?

I have a data file that looks like this:fev.PNG

There are many cases where a value for the column "ActualRead" will not exist, and therefore it will be an estimated read that shows up in the "EstimatedReads" column. My question is how do I combine these two columns so that I have a single column that contains the actual reads, and replaces the missing actual reads with the estimated reads in the other column?

 

P.s. I am a SaS novice. I can handle some programming, but would prefer a solution in EG. Thanks.

Super User
Posts: 8,216

Re: How do I combine multiple numeric columns into one?

Posted in reply to vchfurereyt

The coalesce function will do what you want. e.g.:

data want;
  set have;
  actualreads=coalesce(actualreads,estimatedreads);
run;

Art, CEO, AnalystFinder.com

 

PROC Star
Posts: 1,400

Re: How do I combine multiple numeric columns into one?

Posted in reply to vchfurereyt
data have1;
   set have;
   ActualReads=ifn(missing(ActualReads)=1, EstimatedReads, ActualReads);
run
Super User
Posts: 6,933

Re: How do I combine multiple numeric columns into one?

[ Edited ]
Posted in reply to vchfurereyt

Since you call yourself a novice, I thought you might want the simplest version:

 

data want;

set have;

if ActualReads=. then ActualReads=EstimatedReads;

drop EstimatedReads;

run;

 

Dropping EstimatedReads might not be a great idea, but I wasn't sure if that was part of the question or not.

Ask a Question
Discussion stats
  • 3 replies
  • 345 views
  • 4 likes
  • 4 in conversation