I merged 2 data sets, so that it adds a column to the other set by doing the following:
/* 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;
In this merged data, there is a column with missing values. For those values, I want to compute the mean of that column, and then impute that mean for the missing values. I'm trying to compute the mean and make it a global macro variable:
/* 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 = &q2_mean.;
run;
/* Step 3: Display the data with imputed values */
proc print data=mysas.Surveys_Imputed (obs=10); /* Display first 10 rows */
run;
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?
... View more