Hello,
I have a longitudinal dataset with various features. I want to create a newdataset that is not longitudinal and has new variables that represent the mean, median, and variance measures for each feature by ID!
Data Have:
ID feature1 feature2 feature3
1 7.72 5.43 4.35
1 5.54 2.25 8.22
1 4.43 6.75 2.22
1 3.22 3.21 7.31
2 6.72 2.86 6.11
2 5.89 4.25 5.25
2 3.43 7.30 8.21
2 1.22 3.55 6.55
Data Want:
ID Meanfeature1 Medianfeature1 variancefeature1 Meanfeature2 Medianfeature2 variancefeature2.........
1
2
Any advice on the code?
Thanks!
PROC MEANS
thanks, yes I know proc means gives you the summary statistics and you can get the mean, median and variance.
but I want to generate a whole new dataset showcasing the mean, median, and variance for each feature by ID...
PROC MEANS
What part of PROC MEANS doesn't do what you want?
I wasn't being snarky by the way (though I often am :)).
PROC MEANS is really what you seem to be asking for based on the output. You can merge this back in with your main dataset if you want. You could also use SQL if you wanted this in a single dataset with your original data but MEDIAN wasn't supported in SQL until SAS 9.4 and not everyone is on that system. Plus it generates warnings in the logs that users don't seem to like.
Thanks! no worries. you just answered my question. I was wondering if there was another way of getting the median etc and variance directly....
@Jest wrote:
Thanks! no worries. you just answered my question. I was wondering if there was another way of getting the median etc and variance directly....
What would "directly" mean in this context? Just curious but I see a number of cases where people try to do in a data step what the SAS procedures are intended to accomplish. Often there is much anguish (and often ugly code) trying to replace a 3 or 4 line call to proc means/ summary /univariate or other proc.
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.
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.