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. 

BASUG is hosting free webinars Next up: Mike Raithel presenting on validating data files on Wednesday July 17. Register now at the Boston Area SAS Users Group event page: 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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 282 views
  • 1 like
  • 3 in conversation