I have data with ID, repeated cognitive measure (cog1-cog6), and medication (SSRI) at start. I will eventually run the mixed procedure to determine the association between cognitive score at the time points and SSRI.
My code looks like:
**getting relevant variables;
data ucognition;
set analyze (keep=
HHIDPN SSRI
cog1 cog2 cog3 cog4 cog5 cog6);
run;
proc transpose data=ucognition out=longcog (rename =(col1=CogScore) rename = (_name_=cog));
by HHIDPN SSRI;
var cog1 cog2 cog3 cog4 cog5 cog6;
run;
proc print data=longcog (obs=10);
run;
Through this point, everything works fine (i think?). The following code is where I am trying to create a time variable:
data longcog2;
set longcog;
cog=cog1; time=1; output;
cog=cog2; time=2; output;
cog=cog3; time=3; output;
cog=cog4; time=4; output;
cog=cog5; time=5; output;
cog=cog6; time=6; output;
keep HHIDPN SSRI time cog;
run;
proc print data=longcog2 (obs=10);
run;
Here, SAS says that cog1, cog2, cog3, cog4, cog5, cog6 have not been initialized.
Obs hhidpn SSRI cog time
1 10210020 No SSRI 14 1
2 10210020 No SSRI 13 2
3 10210020 No SSRI 10 3
4 10210020 No SSRI 14 4
5 10210020 No SSRI 10 5
6 10210020 No SSRI 11 6
I am not sure how to fix this, and have tried running various procedures with them, but nothing happens when I try to specifically do the time creation. All of my variables are numeric, so i dont think that is the issue.
I have also tried running like this:
data ucognition;
set analyze (keep=
HHIDPN SSRI
cog1 cog2 cog3 cog4 cog5 cog6);
run;
proc transpose data=ucognition out=longcog (rename =(col1=CogScore) rename = (_name_=cog));
by HHIDPN SSRI **cog1 cog2 cog3 cog4 cog5 cog6**;
var cog1 cog2 cog3 cog4 cog5 cog6
;
run;
proc print data=longcog (obs=10);
run;
data longcog2;
set longcog;
cog=cog1; time=1; output;
cog=cog2; time=2; output;
cog=cog3; time=3; output;
cog=cog4; time=4; output;
cog=cog5; time=5; output;
cog=cog6; time=6; output;
keep HHIDPN SSRI time cog;
run;
proc print data=longcog2 (obs=10);
run;
This works, but it repeats for each person 6 times shown here:
Obs hhidpn SSRI cog time
1 10210020 No SSRI 14 1
2 10210020 No SSRI 13 2
3 10210020 No SSRI 10 3
4 10210020 No SSRI 14 4
5 10210020 No SSRI 10 5
6 10210020 No SSRI 11 6
7 10210020 No SSRI 14 1
8 10210020 No SSRI 13 2
9 10210020 No SSRI 10 3
10 10210020 No SSRI 14 4
11 10210020 No SSRI 10 5
12 10210020 No SSRI 11 6
Is there a reason "cog" which is my rename name=cog variable, wont store cog1-cog6? They are named r7cogtot-r12cogtot in the initial data, but I was told to rename them this way
I transposed to long data as normal. I tried to create a time variable based on the repeated cognition score, but SAS wont let me use 'cog' to hold cog1-cog6 and I am not sure how to fix
The transpose is of
ucognitionwhich apparently has the variablescog1throughcog6.Try
instead of