BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
LOLO
Obsidian | Level 7

Hi!

I'm trying to take the average of a variable and impute that value back into the variable whenever there is a missing value. This code below works except for that I wind up with two variables called cstelass_gr8 and readss_gr8. I need the imputed mean to go directly into the original variable.

proc sql ;

      select cstelass_gr8, readss_gr8, avg(cstelass_gr8) as impmean_ca, avg(readss_gr8) as impmean_pa, i_priorachieve, i_statid,

      case

            when i_priorachieve= 0 and i_statid = "A"

                  then  calculated impmean_ca

      end as cstelass_gr8,

      case

            when i_priorachieve= 0 and  i_statid = "B"

                   then calculated impmean_pa

      end as readss_gr8

     

     

      from a ;

     

quit ;

1 ACCEPTED SOLUTION

Accepted Solutions
LOLO
Obsidian | Level 7

That did it! Thank you so much!

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

The SQL query in your message will not work, it isn't SQL. If you want to impute variables cstelass_gr8 and readss_gr8 with the overall mean, simply use:

proc sql ;

select

  coalesce(cstelass_gr8, mean(cstelass_gr8)) as cstelass_gr8,

  coalesce(readss_gr8,  mean(readss_gr8)) as readss_gr8,

  i_priorachieve,

  i_statid

from a;

quit ;

(not tested)

PG

PG
LOLO
Obsidian | Level 7

That did it! Thank you so much!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2818 views
  • 0 likes
  • 2 in conversation