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

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? 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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.

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
K_Wils15
Obsidian | Level 7
I posted a pic down below of a part of the output. It looks wrong because there are missing values in Std DEV and I am not sure if the code even calculated the difference of the birthweights.
Tom
Super User Tom
Super User

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
Obsidian | Level 7
Thanks!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 5 replies
  • 342 views
  • 0 likes
  • 3 in conversation