Hello,
I am trying to transform this data from wide to long but kept having issues:
data long;
set mental ;
array Avg_hrs_sleep_month(0:2) Avg_hrs_sleep_month0-Avg_hrs_sleep_month2;
array hrs_of_sleep_yest(0:2) hrs_of_sleep_yest0-hrs_of_sleep_yest2;
*Insomnia0 Insomnia1 Insomnia2 see_yourself_6month0 see_yourself_6month1 see_yourself_6month2;
do time=0 to 2;
Avg_hrs_sleep_month = Avg_hrs_sleep_month(time);
hrs_of_sleep_yest= hrs_of_sleep_yest(time);
output;
end;
run;
215 data long;
216 set mental ;
217 array Avg_hrs_sleep_month(0:2) Avg_hrs_sleep_month0-Avg_hrs_sleep_month2;
218 array hrs_of_sleep_yest(0:2) hrs_of_sleep_yest0-hrs_of_sleep_yest2;
219
220 *Insomnia0 Insomnia1 Insomnia2 see_yourself_6month0 see_yourself_6month1 see_yourself_6month2
220! ;
221 do time=0 to 2;
222 Avg_hrs_sleep_month = Avg_hrs_sleep_month(time);
ERROR: Illegal reference to the array Avg_hrs_sleep_month.
223 hrs_of_sleep_yest= hrs_of_sleep_yest(time);
ERROR: Illegal reference to the array hrs_of_sleep_yest.
224 output;
225 end;
226 run;
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.LONG may be incomplete. When this step was stopped there were 0
observations and 46 variables.
WARNING: Data set WORK.LONG was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds
Don't create DATA step variables with the same names as your arrays:
data long;
set mental ;
array Avg_hrs_sleep_month(0:2) Avg_hrs_sleep_month0-Avg_hrs_sleep_month2;
array hrs_of_sleep_yest(0:2) hrs_of_sleep_yest0-hrs_of_sleep_yest2;
*Insomnia0 Insomnia1 Insomnia2 see_yourself_6month0 see_yourself_6month1 see_yourself_6month2;
do time=0 to 2;
Avg_hrs_sleep_mth = Avg_hrs_sleep_month(time);
hrs_of_sleep_yday = hrs_of_sleep_yest(time);
output;
end;
run;
Don't create DATA step variables with the same names as your arrays:
data long;
set mental ;
array Avg_hrs_sleep_month(0:2) Avg_hrs_sleep_month0-Avg_hrs_sleep_month2;
array hrs_of_sleep_yest(0:2) hrs_of_sleep_yest0-hrs_of_sleep_yest2;
*Insomnia0 Insomnia1 Insomnia2 see_yourself_6month0 see_yourself_6month1 see_yourself_6month2;
do time=0 to 2;
Avg_hrs_sleep_mth = Avg_hrs_sleep_month(time);
hrs_of_sleep_yday = hrs_of_sleep_yest(time);
output;
end;
run;
Thank you, this has put me in a state of complete frustration. Thank you
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.