BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
desireatem
Pyrite | Level 9

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

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;

View solution in original post

2 REPLIES 2
SASKiwi
PROC Star

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;
desireatem
Pyrite | Level 9

Thank you, this has put me in a state of complete frustration. Thank you

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

What is ANOVA?

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.

Discussion stats
  • 2 replies
  • 710 views
  • 3 likes
  • 2 in conversation