## array problem

Solved
Occasional Contributor
Posts: 17

# array problem

Hello guys,

need help by using ARRAY on tranform this

ID          X1          X2        X3         X4         X5         Y1          Y2          Y3        Y4          Y5

 1 4 5 4 7 3 1 7 3 6 8 2 8 7 8 6 7 5 4 3 5 6

into this form.

ID          Time          X             Y
01           1              4              5
01           2              5              7

01           3              4              3

01           4              7              6

here is my code

DATA FROG;
INPUT ID X1-X5 Y1-Y5;
DATALINES;
01 4 5 4 7 3 1 7 3 6 8
02 8 7 8 6 7 5 4 3 5 6
;
proc
print data = frog;

and here is my log

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
61
62 DATA FROG;
63 INPUT ID X1-X5 Y1-Y5;
64 DATALINES;

NOTE: The data set WORK.FROG has 2 observations and 11 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.02 seconds

67 ;

68 proc
69 print data = frog;
70
71 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
84

thank you guys

Accepted Solutions
Solution
‎07-24-2017 03:06 PM
Super User
Posts: 8,260

## Re: array problem

You probably want to use the ARRAY statement to help you deal with an array problem.

Looks like you have an X and a Y array.

data have;
input id x1-x5 y1-y5 ;
cards;
1	4	5	4	7	3	1	7	3	6	8
2	8	7	8	6	7	5	4	3	5	6
;
data want ;
set have ;
array _x x1-x5 ;
array _y y1-y5 ;
do time=1 to dim(_x);
x=_x(time);
y=_y(time);
output;
end;
drop x1-x5 y1-y5 ;
run;

proc print;
run;

All Replies
Solution
‎07-24-2017 03:06 PM
Super User
Posts: 8,260

## Re: array problem

You probably want to use the ARRAY statement to help you deal with an array problem.

Looks like you have an X and a Y array.

data have;
input id x1-x5 y1-y5 ;
cards;
1	4	5	4	7	3	1	7	3	6	8
2	8	7	8	6	7	5	4	3	5	6
;
data want ;
set have ;
array _x x1-x5 ;
array _y y1-y5 ;
do time=1 to dim(_x);
x=_x(time);
y=_y(time);
output;
end;
drop x1-x5 y1-y5 ;
run;

proc print;
run;
☑ This topic is solved.

Discussion stats