Hello!
I'm trying to count, how many times in total did the respondents answer a question X during the longitudinal study. I would like to have a mean and standard deviation.
Example:
NAME QUESTION X QUESTION X QUESTION X
AT POINT 1 AT POINT 2 AT POINT 3
Matt 3 2 1 (three times)
Lisa 4 4 (two times)
Anne 3 2 (two times)
Karl 3 (one time)
I would like to know how many times in total (mean and SD) the participants provided information on the question X? In the example, I can see that the mean is 2, but I don't know how to make the script in SAS.
Thank you so much for your help!
data have ;
infile cards ;
input
name $
q1
q2
q3 ;
cards ;
matt 3 2 1
lisa 4 . 4
anne . 3 2
karl 3 . .
;
data have2;
set have;
qcnt = n(of q1-q3);
run;
proc means data=temp1 ;
var qCnt ;
run ;
Here's one way to do it using some data step then pushing the results into PROC MEANS
/* Create Test Data */
data have ;
infile cards ;
input
name $
q1 $
q2 $
q3 $ ;
cards ;
matt 3 2 1
lisa 4 . 4
anne . 3 2
karl 3 . .
;
/* Add variable that counts number of responses to questions */
data temp1 ;
set have ;
array qs{3} q1-q3 ;
qCnt=0 ;
do i=1 to 3 ;
if not missing(qs{i}) then
qCnt+1 ;
/* output values to log for testing */
put name= qs{i}= qCnt= numberOfObs= ;
end ;
/* Output observation */
output ;
run ;
/* PROC MEANS provides mean and standard deviation */
proc means data=temp1 ;
var qCnt ;
run ;
data have ;
infile cards ;
input
name $
q1
q2
q3 ;
cards ;
matt 3 2 1
lisa 4 . 4
anne . 3 2
karl 3 . .
;
data have2;
set have;
qcnt = n(of q1-q3);
run;
proc means data=temp1 ;
var qCnt ;
run ;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.