BookmarkSubscribeRSS Feed
nwang5
Obsidian | Level 7

Hi SAS Communities, I tried to use the mean to represent the missing value, but it still showed there were missing value.

 

 

data elsa02(drop = a _a m);

_a = a;

do _N_ = 1 by 1 until (last.idauniq | a);
set elsa01(rename = drinkd = a);
by idauniq ;
end;

m = mean(_a, a);

do _N_ = 1 to _N_;
set elsa01(rename = drinkd = a);
drinkd = coalesce(a, m);
output;
end;

run;

 

NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
444 at 935:8
NOTE: There were 45648 observations read from the data set WORK.ELSA01.
NOTE: There were 45648 observations read from the data set WORK.ELSA01.
NOTE: The data set WORK.ELSA02 has 45648 observations and 50 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.01 second

 

 

2 REPLIES 2
Quentin
Super User

It's hard to tell from your code what you are trying to do, or what mean you want to calculate.

 

Could you edit your question to show some sample data (5 - 10 records made with a data step with cards statement), then run your code on that data, and describe how your results differ from the results you want?

 

It looks like your code should run without errors.  But I can't quite tell the intent. 

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
PGStats
Opal | Level 21

Maybe all you want is :

 

proc sql;
create table elsa02 as
select *,
	coalesce(drinkd, mean(drinkd)) as newDrinkd
from elsa01
group by idauniq;
quit;

i.e. replace missing drinkd values with the mean of drinkd values in the same idauniq group.

PG

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
  • 391 views
  • 1 like
  • 3 in conversation