BookmarkSubscribeRSS Feed
Jest
Obsidian | Level 7

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!

 

 

 

7 REPLIES 7
Jest
Obsidian | Level 7

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

 

Reeza
Super User

PROC MEANS

 

What part of PROC MEANS doesn't do what you want?

Reeza
Super User

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. 

 

DELETE_proc_means.JPG

Jest
Obsidian | Level 7

Thanks! no worries. you just answered my question. I was wondering if there was another way of getting the median etc and variance directly....

 

 

ballardw
Super User

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

Peter_C
Rhodochrosite | Level 12
Would the Univariate Procedure offer another way?

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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