BookmarkSubscribeRSS Feed
fieldsa83
Quartz | Level 8

Right now I'm doing a (weighted) proc means by sex then doing a data step to subract women's avg from men's. There's also a few redundant steps.

 

I'd like to try and do it in 1 step using maybe proc tabulate? Not sure if you have any advice.

 

thanks!

3 REPLIES 3
PaigeMiller
Diamond | Level 26

It would be hard to actually provide a solution in one step unless you show us (a portion of) your data.

 

But as far as advice goes, doing it in one step sometimes is harder than doing it in several steps. Again, we can't advise this without seeing your data, and without seeing your existing code.

 

Lastly, I ask ... why does it need to be done in one step? There are other possible more meaningful goals: efficiency of execution, readability of code. To be honest, I think doing it in one step is a false goal most of the time; it shows you are a wizard at coding, but that's rarely a goal in most business situations.

--
Paige Miller
PaigeMiller
Diamond | Level 26

Also, PROC TTEST provides weighted means by group, and also computes the difference between the two groups without a need for additional programming. This may not be particularly efficient, as TTEST will also compute a lot of other things you don't want, but it still spends the time to do the calculations.

--
Paige Miller
ballardw
Super User

@fieldsa83 wrote:

Right now I'm doing a (weighted) proc means by sex then doing a data step to subract women's avg from men's. There's also a few redundant steps.

 

I'd like to try and do it in 1 step using maybe proc tabulate? Not sure if you have any advice.

 

thanks!


Proc tabulate will not do calculations involving resulting statistics as you would need for this.

Proc Report might depending on your actual data. However if you start getting into moderately complex comparisons such as by sex, age and some geographical area the approach in Proc Report could become quite complex and fragile.

 

What are "redundant steps" in your process?

 

I could see a proc means, proc transpose, data step and proc print or perhaps proc tabulate or report to display results as typical for this type of report.

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
  • 3 replies
  • 487 views
  • 2 likes
  • 3 in conversation