Hi I'm having trouble transposing my wide-format data back to long form. I need to include a variable, TIME, which can be either "1" or "2". The code I am using successfully codes my variables back to the long form, but I can't work out how to get it to add "TIME" as a column as well. Currently each variable in the long form either has a "1" or "2" at the end of the name to denote TIME.
Each ID has a Time "1" and a Time "2", so the long form should look like this:
ID TIME VARIABLE
1234 1 etc
1234 2
4321 1
4321 2
Here is my code:
DATA LONGGEE;
SET WORK.IMPORT5;
TIME=1
ADL=ADL1;
COGTOTSAS=COGTOTSAS1;
FAC=FAC1;
GDS=GDS1;
NHP=NHP1;
PEFITTOTSAS=PEFITTOTSAS1;
SD=SD1;
SOCTOTSAS=SOCTOTSAS1;
OUTPUT;
TIME=2
ADL=ADL2;
COGTOTSAS=COGTOTSAS2;
FAC=FAC2;
GDS=GDS2;
NHP=NHP2;
PEFITTOTSAS=PEFITTOTSAS2;
SD=SD2;
SOCTOTSAS=SOCTOTSAS2;
OUTPUT;
KEEP Obs _Imputation_ ID ADL COGTOTSAS FAC GDS NHP PEFITTOTSAS SD SOCTOTSAS TIME;
RUN;
Thank you!
Are you sure? Your code looks correct, can you post your log and output?
Your KEEP statement should be dropping all your 1/2 variables.
@rebeccachau wrote:
Hi I'm having trouble transposing my wide-format data back to long form. I need to include a variable, TIME, which can be either "1" or "2". The code I am using successfully codes my variables back to the long form, but I can't work out how to get it to add "TIME" as a column as well. Currently each variable in the long form either has a "1" or "2" at the end of the name to denote TIME.
Each ID has a Time "1" and a Time "2", so the long form should look like this:
ID TIME VARIABLE
1234 1 etc
1234 2
4321 1
4321 2
Here is my code:
DATA LONGGEE;
SET WORK.IMPORT5;
TIME=1
ADL=ADL1;
COGTOTSAS=COGTOTSAS1;
FAC=FAC1;
GDS=GDS1;
NHP=NHP1;
PEFITTOTSAS=PEFITTOTSAS1;
SD=SD1;
SOCTOTSAS=SOCTOTSAS1;
OUTPUT;
TIME=2
ADL=ADL2;
COGTOTSAS=COGTOTSAS2;
FAC=FAC2;
GDS=GDS2;
NHP=NHP2;
PEFITTOTSAS=PEFITTOTSAS2;
SD=SD2;
SOCTOTSAS=SOCTOTSAS2;
OUTPUT;
KEEP Obs _Imputation_ ID ADL COGTOTSAS FAC GDS NHP PEFITTOTSAS SD SOCTOTSAS;
RUN;
Thank you!
Hi,
It's not producing any output because of errors. I have also attached the data in case that's helpful.
Here is the log:
you need to add a semicolon after
TIME=1;
Cripes! Thanks so much.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.