Hi,
I am trying to create a new variable that is the average of a variable V1 for every subject. Each subject has 3 rows containing values for V1 that were taken at 3 different time points. I can't calculate the average using a data step: average=(total_V1 / 3) because some subjects have 1-3 missing values for V1. Therefore, for those subjects that are missing V1 values it should be divided by 1 or 2 for example not 3. I can't figure out how to create a variable to go in the denominator of my average calculation to make the numbers accurate, please help!
Here is an example of how the data exists:
id. V1
1. 3
1. 4
1. 5
2. 6
2. .
2. 7
3. .
3. .
3. 2
You should always show what you expect an output data set to look like. Do you need a data set for further manipulation or a report for people read?
One way to get a data set:
proc summary data=have nway; class id; var v1; output out=summary (drop=_:) mean=; run;
@meghanrm wrote:
Sorry I am new to posting on here. I need a data set for further manipulation. I am trying to create a new average variable and I have already written the code to get the total for the numerator of the average calculation but I can't figure out what code would work for the denominator being that subjects with missing data should not be divided by 3
Use PROC SUMMARY, as explained by @ballardw and then do the "further manipulation" in the output from PROC SUMMARY.
Which brings up the question: what "further manipulation" do you want to do? Perhaps this is already available in SAS (for example, PROC STDIZE) and so maybe PROC SUMMARY isn't needed.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.