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

Hello,

 

I want to write a proc mean code to display only women who are married in my data-set. 

The variable name is Marital_Status coded as  (1=Married, 0 = not married)

 

My SAS code is:

proc means data = hattis7 missing mean std sum nway;
var stratus weightus;
class Marital_Status;
output out = Martial_Status;
run;

 

The problem i have is that when i run this code, it gives me a summary statistics for both 1 (Married) and 0 (not married).

How do i get an output that give me a summary statistic for ONLY people who are married (1).

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

You would replace the CLASS statement with:

 

where Marital_Status=1;

 

Also, is this a Freudian slip?

 

output out = Martial_Status;

 

You may need to add to the OUTPUT statement.  Statistics requested on the PROC statement (mean std sum) apply to the printed report only.

 

Finally, does your entire DATA step contain women only?  You might need to add something to the logic such as:

 

where Marital_Status=1 and gender="F";

View solution in original post

8 REPLIES 8
Astounding
PROC Star

You would replace the CLASS statement with:

 

where Marital_Status=1;

 

Also, is this a Freudian slip?

 

output out = Martial_Status;

 

You may need to add to the OUTPUT statement.  Statistics requested on the PROC statement (mean std sum) apply to the printed report only.

 

Finally, does your entire DATA step contain women only?  You might need to add something to the logic such as:

 

where Marital_Status=1 and gender="F";

Reeza
Super User

You can add a WHERE statement, but you're filtering on two variables here, not just one. 

 

proc means ....;
where marital_status=1 and sex = 'F';

The exact code will depend on how the sex is recorded in your data and what the values hold. 

 


@ChuksManuel wrote:

Hello,

 

I want to write a proc mean code to display only women who are married in my data-set. 

The variable name is Marital_Status coded as  (1=Married, 0 = not married)

 

My SAS code is:

proc means data = hattis7 missing mean std sum nway;
var stratus weightus;
class Marital_Status;
output out = Martial_Status;
run;

 

The problem i have is that when i run this code, it gives me a summary statistics for both 1 (Married) and 0 (not married).

How do i get an output that give me a summary statistic for ONLY people who are married (1).

 

Thanks


 

ChuksManuel
Pyrite | Level 9

Thank you. They are all F

ChuksManuel
Pyrite | Level 9

Hey Reeza,

 

I wanted to ask you one more question.

 I wanted to write a SAS code  using proc means to create just one dataset that contains the minimum, maximum and median for the variables "weight" and "height" and i want to calculate these statistics for each unique combination of "Race" and "smok_status".

 

Please how do i go about this if i want to use the "noprint" option to suppress the output to the Output window.

PaigeMiller
Diamond | Level 26

@ChuksManuel wrote:

Hey Reeza,

 

I wanted to ask you one more question.

 I wanted to write a SAS code  using proc means to create just one dataset that contains the minimum, maximum and median for the variables "weight" and "height" and i want to calculate these statistics for each unique combination of "Race" and "smok_status".

 

Please how do i go about this if i want to use the "noprint" option to suppress the output to the Output window.


proc summary data=have nway;
    class race smok_status;
    var weight height;
    output out=stats min= max= median= /autoname;
run;
--
Paige Miller
ChuksManuel
Pyrite | Level 9

Thank you Paige. Please help me critique this code.

1. I want to calculate the average of baby's weight for each group defined by level of smoking status by marital status.

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

3. Exclude observations with missing data on the relevant variables from the calculations. 

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

5. Finally what do i do with the _TYPE_ variable?

 

Proc means data = work.data1 mean;

class momsmoke married;

var weight;

output out = group_mean (where = (_type_ =3))

mean (weight) = mean_wt;

run;

 

proc sort data = group_mean out=gm;

by momsmoke married;

run;

proc sort data = sashelp.bweight out=Indwt;

by momsmoke married;

run;

 

 

Data gmIndwt;

merge gm Indwt;

by momsmoke married;

wt_diff= weight - mean_wt;

run;

 

proc print data = gmindwt;

 

 

PaigeMiller
Diamond | Level 26

@ChuksManuel wrote:

Thank you Paige. Please help me critique this code.

1. I want to calculate the average of baby's weight for each group defined by level of smoking status by marital status.

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

3. Exclude observations with missing data on the relevant variables from the calculations. 

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

5. Finally what do i do with the _TYPE_ variable?


 

For steps 1 and 2:

Use PROC STDIZE with METHOD=MEAN and a BY statement. This will subtract the mean of the values in each group from the actual values.

 

Step 3: This is also done by PROC STDIZE, observations with a missing value of weight will remain missing.

 

Step 4: I'm lost, how does this differ from steps 1 and 2?

 

Step 5: You can do whatever you want with the _TYPE_ variable.

--
Paige Miller
ChuksManuel
Pyrite | Level 9

Thank you Paige

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!

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
  • 8 replies
  • 1099 views
  • 2 likes
  • 4 in conversation