Hi SAS coders,
I am trying to restructure a dataset using an array and do loop and I keep getting errors. My datelines are:
DATA WORK.SwimMinutes;
INFILE DATALINES;
INPUT Name $1-5
Age 7-8
Mon 10-11
Tues 13-14
Wed 16-17 ;
DATALINES;
Ann 26 51 19 22
Bob 30 43 20 60
Chris 41 48 . 36
Dina 21 32 57 22
;
My code that I have used is:
DATA WORK.SwimLog2;
SET WORK.SwimMinutes;
BY Name;
ARRAYDay{*} Day1 - Day3;
DO i = 1 TO DIM(Day);
Day = Day{i};
IF MISSING(Day) = 0 THEN OUTPUT;
END;
DROP i Day1 - Day3;
RUN;
The end dataset result should look like:
SAS Data Set ‘SwimLong2’ | 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 | … | … | … | … | … | 12 | Dina | 21 | 3 | 22 | … | … | … | … | … |
Please advise |