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 is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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