<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Imputing the mean for missing the values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Imputing-the-mean-for-missing-the-values/m-p/953217#M372451</link>
    <description>&lt;P&gt;Alternative to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;code.&lt;BR /&gt;I am using the&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;if _N_=1 then set&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;technique.&lt;/P&gt;
&lt;P&gt;(as others told you before no macro variables are needed for this)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Alternative to Ksharp's code */
data have;
 set sashelp.class;
 if _n_ in (4:8) then call missing(height,weight);
run;

*proc stdize data=have out=want missing=mean reponly;
*var height weight;
*run;

proc means data=have noprint;
 var height weight;
 output out=have_means(drop=_:) mean= / autoname;
run;

data want(drop=height_mean weight_mean);
 if _N_=1 then set have_means;
 set have;
 if height=. then height=height_mean;
 if weight=. then weight=weight_mean;
run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
    <pubDate>Wed, 11 Dec 2024 11:49:22 GMT</pubDate>
    <dc:creator>sbxkoenk</dc:creator>
    <dc:date>2024-12-11T11:49:22Z</dc:date>
    <item>
      <title>Imputing the mean for missing the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Imputing-the-mean-for-missing-the-values/m-p/953163#M372447</link>
      <description>&lt;P&gt;I merged 2 data sets, so that it adds a column to the other set by doing the following:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* read datasets */
libname mysas "Path to file folder";

data mysas.Surveys;
  set mysas.surveyresults; 
run;

data mysas.APIdata;
  set mysas.api; 
run;

libname mysas "Path to file folder";

data surveys2;
  set mysas.surveyresults;
  if not missing(q1); /* Remove rows with missing inputs */
run;

data mergeddat;
  merge surveys2 (in=inS) mysas.api (in=inA);
  by SchoolName;
  if inS; /* Keep only schools from the survey results */
run;

proc sort data=mergeddat;
  by SchoolName;
run;

/* Verify added column */
proc print data=mergeddat (obs=5);
run;

/* Verify row count */
proc contents data=mergeddat;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In this merged data, there is a column with missing values. For those values, &lt;U&gt;&lt;STRONG&gt;I want to compute the mean of that column, and then impute that mean for the missing values.&lt;/STRONG&gt;&lt;/U&gt; I'm trying to compute the mean and make it a global macro variable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;/* Compute the mean of q2 and create a global macro variable */
proc means data=mysas.Surveys noprint;
  var q2;
  output out=q2_mean_data mean=mean_q2;
run;

/* Extract the computed mean into a macro variable */
data _null_;
  set q2_mean_data;
  call symputx('q2_mean', mean_q2);
run;

/* Impute missing values in q2 using the computed mean */
data mysas.Surveys_Imputed;
  set mysas.Surveys;
  if missing(q2) then q2 = &amp;amp;q2_mean.;
run;

/* Step 3: Display the data with imputed values */
proc print data=mysas.Surveys_Imputed (obs=10); /* Display first 10 rows */
run;&lt;/PRE&gt;
&lt;P&gt;However, when I try to get a visual, nothing is outputting when I do proc print. I feel like my logic and approach should accomplish this. What am I doing wrong and how can I fix this?&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2024 05:15:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Imputing-the-mean-for-missing-the-values/m-p/953163#M372447</guid>
      <dc:creator>unwashedhelimix</dc:creator>
      <dc:date>2024-12-11T05:15:40Z</dc:date>
    </item>
    <item>
      <title>Re: Imputing the mean for missing the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Imputing-the-mean-for-missing-the-values/m-p/953168#M372448</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 set sashelp.class;
 if _n_ in (4:8) then call missing(height,weight);
run;

proc stdize data=have out=want missing=mean reponly;
var height weight;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Dec 2024 06:44:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Imputing-the-mean-for-missing-the-values/m-p/953168#M372448</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-12-11T06:44:43Z</dc:date>
    </item>
    <item>
      <title>Re: Imputing the mean for missing the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Imputing-the-mean-for-missing-the-values/m-p/953169#M372449</link>
      <description>&lt;P&gt;Please post the complete log, so that we see what happened actually.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2024 06:45:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Imputing-the-mean-for-missing-the-values/m-p/953169#M372449</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2024-12-11T06:45:52Z</dc:date>
    </item>
    <item>
      <title>Re: Imputing the mean for missing the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Imputing-the-mean-for-missing-the-values/m-p/953198#M372450</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;In this merged data, there is a column with missing values. For those values, &lt;U&gt;&lt;STRONG&gt;I want to compute the mean of that column, and then impute that mean for the missing values.&lt;/STRONG&gt;&lt;/U&gt; I'm trying to compute the mean and make it a global macro variable:&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no need for a macro variable here. SAS has many PROCs to do what are standard statistical methods, which you should investigate (or ask us about) before you decide to create your own code to do a standard statistical method, and before you decide to create macro variables. As &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt; points out, PROC STDIZE will do this for you.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2024 10:56:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Imputing-the-mean-for-missing-the-values/m-p/953198#M372450</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-12-11T10:56:16Z</dc:date>
    </item>
    <item>
      <title>Re: Imputing the mean for missing the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Imputing-the-mean-for-missing-the-values/m-p/953217#M372451</link>
      <description>&lt;P&gt;Alternative to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;code.&lt;BR /&gt;I am using the&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;if _N_=1 then set&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;technique.&lt;/P&gt;
&lt;P&gt;(as others told you before no macro variables are needed for this)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Alternative to Ksharp's code */
data have;
 set sashelp.class;
 if _n_ in (4:8) then call missing(height,weight);
run;

*proc stdize data=have out=want missing=mean reponly;
*var height weight;
*run;

proc means data=have noprint;
 var height weight;
 output out=have_means(drop=_:) mean= / autoname;
run;

data want(drop=height_mean weight_mean);
 if _N_=1 then set have_means;
 set have;
 if height=. then height=height_mean;
 if weight=. then weight=weight_mean;
run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2024 11:49:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Imputing-the-mean-for-missing-the-values/m-p/953217#M372451</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2024-12-11T11:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: Imputing the mean for missing the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Imputing-the-mean-for-missing-the-values/m-p/953221#M372452</link>
      <description>&lt;P&gt;I point out that for SASHELP.CLASS, there are a very small number of variables. If the real data set has lots of variables, and they each need to have their own mean imputed when a value is missing, then the approach from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/60547"&gt;@sbxkoenk&lt;/a&gt;&amp;nbsp;is a lot of typing, but PROC STDIZE is much less typing.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2024 12:23:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Imputing-the-mean-for-missing-the-values/m-p/953221#M372452</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-12-11T12:23:07Z</dc:date>
    </item>
    <item>
      <title>Re: Imputing the mean for missing the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Imputing-the-mean-for-missing-the-values/m-p/953222#M372453</link>
      <description>&lt;P&gt;Fixing what I believe is a typo in&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;'s program&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc stdize data=have out=want missing=mean reponly;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;should say&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc stdize data=have out=want method=mean reponly;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Dec 2024 12:20:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Imputing-the-mean-for-missing-the-values/m-p/953222#M372453</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-12-11T12:20:06Z</dc:date>
    </item>
    <item>
      <title>Re: Imputing the mean for missing the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Imputing-the-mean-for-missing-the-values/m-p/953224#M372454</link>
      <description>Nope, Plz check the result and the LOG.</description>
      <pubDate>Wed, 11 Dec 2024 12:34:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Imputing-the-mean-for-missing-the-values/m-p/953224#M372454</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-12-11T12:34:26Z</dc:date>
    </item>
  </channel>
</rss>

