Here is the problem:
Using the SAS data set SASHELP.BWEIGHT, write all the SAS code necessary to calculate the average of baby's weight for each group defined by level of smoking status by marital status. Then calculate the difference between the individual baby's weight and the average weight for the babies in the group defined by mother's smoking status and marital status. Exclude observations with missing data on the relevant variables from the calculations. To solve this problem you will need to use Proc Means to find the average weight for babies in each condition and then do a merge so the values are available to find the difference for individual babies. Hint – Be sure to consider what to do with the _TYPE_ variable.
Here is what I have:
proc means data=sashelp.bweight Nway ;
var MomSmoke Married ;
class Weight ;
output out= Avg_Weight_Mean
Mean (MomSmoke Married) = mean_smk mean_mar;
run;
proc sort data=Avg_Weight_Mean out=new_stat_undup;
by Weight;
run;
proc sort data=sashelp.bweight out=bweight2;
by Weight;
run;
data bweight3;
merge new_stat_undup (in=a) bweight2 (in=b);
by Weight;
if a;
Smoke_diff = Momsmoke - mean_smk;
Married_diff = Married - mean_mar;
run;
proc means data=bweight3 mean stddev;
class Weight;
var Smoke_diff Married_diff;
run;
The output looks weird and long and I just realized that I get confused with the class and var. Just wondering if someone could double check this for me?
You do seem to have the class and var reversed.
CLASS is for breaking your data into groups.
VAR is the numeric variable you want to analyze.
Looks like you want to analyze WEIGHT and check it in the different classes defined by the values of smoking and marriage.
@K_Wils15 wrote:
The output looks weird and long and I just realized that I get confused with the class and var. Just wondering if someone could double check this for me?
Show us the output, and explain in words what is "weird" and doesn't seem correct.
To show us the output, paste the output as text into the window that appears when you click on the {i} button; or show us a screen capture of the output.
You do seem to have the class and var reversed.
CLASS is for breaking your data into groups.
VAR is the numeric variable you want to analyze.
Looks like you want to analyze WEIGHT and check it in the different classes defined by the values of smoking and marriage.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.