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

I am trying to make an output dataset in this format:

 

Name

Age

Day

Minutes

1

Ann

26

1

51

2

Ann

26

2

19

3

Ann

26

3

22

4

Bob

30

1

43

5

Bob

30

2

20

6

Bob

30

3

60

 

Here is the instream data I am using and the start of my DATA step. I am confused as to how I set up the array to accomplish the task of combining the Mon, Tue, Wed variable into a Minutes variable

 

data work.swimminutes;
infile datalines delimiter = ',';
input Name :$5.
Age :2.
Mon :2.
Tues :2.
Wed :2.;
datalines;
Ann,26,51,19,22
Bob,30,43,20,60
Chris,41,48,.,36
Dina,21,32,57,22
;

data Work.SwimLong2;
set WORK.SwimMinutes;
array ???;
do Day = 1 TO 3;
output;
end;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You declared your array correctly, but you never use it anywhere. 

I've added the relevant line below, as a spoiler. I would recommend you try it first yourself but the answer is there if you need it.

 

 

 

Spoiler

data Work.SwimLong2;
set WORK.SwimMinutes;
Array Minutes (3) Mon Tues Wed;
do Day = 1 TO 3;

 

Value = Minutes(day);

 

output;
end;
run;

View solution in original post

6 REPLIES 6
Reeza
Super User

You've declared arrays in your previous posts, why the issue in not knowing how to declare an array here?

 


data Work.SwimLong2;
set WORK.SwimMinutes;
array ???; 
do Day = 1 TO 3;
output;
end;
run;


 

marianhabesland
Calcite | Level 5

The arrays I have done in the past have been different because I have been creating variables, but in this case I have to change the data set to have a variables that are currently horizontal, in this case Mon Tues Wed and make a variable called Minutes that changes these variables into a format with them all in one column. It is just a different situation, so that is why I am a bit confused. The things I have tried so far just haven't worked.

Reeza
Super User

Post what you've tried then.

marianhabesland
Calcite | Level 5

This is what I tried but it obviously does not produce the desired results as it still produces the Mon Tues and Wed columns, but just repeats the observations in the DO loop.

 

data work.swimminutes;
infile datalines delimiter = ',';
input Name :$5.
Age :2.
Mon :2.
Tues :2.
Wed :2.;
datalines;
Ann,26,51,19,22
Bob,30,43,20,60
Chris,41,48,.,36
Dina,21,32,57,22
;

data Work.SwimLong2;
set WORK.SwimMinutes;
Array Minutes (3) Mon Tues Wed;
do Day = 1 TO 3;
output;
end;
run;

Reeza
Super User

You declared your array correctly, but you never use it anywhere. 

I've added the relevant line below, as a spoiler. I would recommend you try it first yourself but the answer is there if you need it.

 

 

 

Spoiler

data Work.SwimLong2;
set WORK.SwimMinutes;
Array Minutes (3) Mon Tues Wed;
do Day = 1 TO 3;

 

Value = Minutes(day);

 

output;
end;
run;

marianhabesland
Calcite | Level 5

That makes sense. I felt like I was missing the place where the array was actually referenced, I think I just struggled with how to reference it.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1957 views
  • 0 likes
  • 2 in conversation