BookmarkSubscribeRSS Feed
jjoliver1981
Calcite | Level 5


Hi,

I need to create a table which shows the proportional split by variable in a number of weeks.  Easy enough via summary table / proc tabulate.  Example below.

PropValuesByWeek.png

    I then need to be able to lookup the intersection value of week 1 and 45 to 49 and return it into my table data so that every transaction line has the appropriate percentage.

I'll then use this to reweight my batch of data.

The time periods I have go over a couple of years.

In excel terms this feels like a lookup with an IF nested, though it's a massive nest.

I have a workaround which involves exports, calculating in excel and imports but I'd keep it clean in SAS EG.

Any help is appreciated.

Thanks,

JJ


 
 
 
 
 
 
 
 
 
 
 





4 REPLIES 4
ballardw
Super User

Does the "week" imply a year? As in when you compare date such as Jan 1 2012 and Jan 1 2014 are they both in week 1?

What rule are you using for assigning date to week? SAS natively supports 3 different rules, look in the documentation for the function WEEK and descriptors U, V and W.

Are your dates SAS date values?

Are your ages numeric with the value displayed the result of a format or are they those character strings (goes to writing comparison logic)?

This may be easier if your lookup data is in the long form of

Age(range) WeekNumber Value

jjoliver1981
Calcite | Level 5

It's from a SAS data set so yes the dates are in SAS format.

I've put a week format over the top of that to create my week column.

Therefore in your example yes those week 1's are comparable.

The ages are character strings generated from a format applied with a put.

I absolutely agree it would be easier to have it as a long form, however I do not know in SAS how to so it so that all of week1 adds to 100% then all of week2 adds to 100%.  Any advice there is appreciated?  Perhaps a version of group by... might work

ballardw
Super User

It may help to print 10 or so lines to show the actual structure of the dataset. Your comment about "adding to %100" makes me think that the example data you showed is not what you are starting with. Describe what you start with and the desired result.

jjoliver1981
Calcite | Level 5

Hi,

This is a sas data set so the data is in SAS format.

I've put formats over the top of it.  The picture in the message is just an example rather than the exact format.  My dates show in sas as 13W14 for example.

Ages are characters strings.

I would ideally like to have a list that I can lookup into so that long form that you describe would be ideal (there will be many variables included).

However, I don't know how to get sas to generate this % of the first variable.

I've been playing around with proc freq and the outpct but once I get to 4 variables, it stops working.  The overall percent figure generated is inaccurate.

My variables are A, B C, D, E,

I need to know what percentage each element of E is of element A.

A in this instance is the week number

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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