Hello experts! I need to use an array to make my data table, but for some reason the data in the last column isn't being output. Here is the directions for my problem:
Patients underwent knee replacement surgeries for one or both knees. The data record patient id, the replaced knee number (1 or 2), and satisfaction scores pre-operatively, one day, one week, and one month after the surgery. The data are
|
(a) Use the ARRAY statement to create a data set containing satisfaction scores for knee 1.
(b) Use the ARRAY statement to create a data set containing satisfaction scores for knee 2.
(c) Use the MERGE statement to create the merged file
Here is my code for part a:
data exercise3;
input ID $ KneeNumber PreOp OneDay OneWeek OneMonth;
cards;
01 1 0 5 7 10
02 1 0 10 15 15
02 2 3 5 8 10
03 1 0 3 3 3
03 2 0 6 9 9
04 1 0 4 10 10
;
data A (keep=id visit score);
set exercise3;
array x{4} preop day1 week1 month1;
do i=1 to 4;
visit = i;
score = x{i};
if kneenumber = 1;
output;
end;
run;
proc print noobs;
run;
And this is my output:
@user1942 wrote:
Hello experts! I need to use an array to make my data table, but for some reason the data in the last column isn't being output. Here is the directions for my problem:
Patients underwent knee replacement surgeries for one or both knees. The data record patient id, the replaced knee number (1 or 2), and satisfaction scores pre-operatively, one day, one week, and one month after the surgery. The data are
Patient Knee Score Score at Score at Score at
ID Number Pre-op one day one week one month
01 1 0 5 7 10
02 1 0 10 15 15
02 2 3 5 8 10
03 1 0 3 3 3
03 2 0 6 9 9
04 1 0 4 10 10
(a) Use the ARRAY statement to create a data set containing satisfaction scores for knee 1.
(b) Use the ARRAY statement to create a data set containing satisfaction scores for knee 2.
(c) Use the MERGE statement to create the merged file
Here is my code for part a:
data exercise3;
input ID $ KneeNumber PreOp OneDay OneWeek OneMonth;
cards;
01 1 0 5 7 10
02 1 0 10 15 15
02 2 3 5 8 10
03 1 0 3 3 3
03 2 0 6 9 9
04 1 0 4 10 10
;
data A (keep=id visit score);
set exercise3;
array x{4} preop day1 week1 month1;
do i=1 to 4;
visit = i;
score = x{i};
if kneenumber = 1;
output;
end;
run;
proc print noobs;
run;
And this is my output:
ID visit score01 1 0
01 2 .
01 3 .
01 4 .
02 1 0
02 2 .
02 3 .
02 4 .
03 1 0
03 2 .
03 3 .
03 4 .
04 1 0
04 2 .
04 3 .
04 4 .I'm not sure what I'm doing wrong, please help!!!
Please closely examine the names of the variables highlighted.
An array statement will create new variables if the name referenced on the array statement does not already exist.
You used three variable names on the array statement that were not already in the input data set.
@user1942 wrote:
Hello experts! I need to use an array to make my data table, but for some reason the data in the last column isn't being output. Here is the directions for my problem:
Patients underwent knee replacement surgeries for one or both knees. The data record patient id, the replaced knee number (1 or 2), and satisfaction scores pre-operatively, one day, one week, and one month after the surgery. The data are
Patient Knee Score Score at Score at Score at
ID Number Pre-op one day one week one month
01 1 0 5 7 10
02 1 0 10 15 15
02 2 3 5 8 10
03 1 0 3 3 3
03 2 0 6 9 9
04 1 0 4 10 10
(a) Use the ARRAY statement to create a data set containing satisfaction scores for knee 1.
(b) Use the ARRAY statement to create a data set containing satisfaction scores for knee 2.
(c) Use the MERGE statement to create the merged file
Here is my code for part a:
data exercise3;
input ID $ KneeNumber PreOp OneDay OneWeek OneMonth;
cards;
01 1 0 5 7 10
02 1 0 10 15 15
02 2 3 5 8 10
03 1 0 3 3 3
03 2 0 6 9 9
04 1 0 4 10 10
;
data A (keep=id visit score);
set exercise3;
array x{4} preop day1 week1 month1;
do i=1 to 4;
visit = i;
score = x{i};
if kneenumber = 1;
output;
end;
run;
proc print noobs;
run;
And this is my output:
ID visit score01 1 0
01 2 .
01 3 .
01 4 .
02 1 0
02 2 .
02 3 .
02 4 .
03 1 0
03 2 .
03 3 .
03 4 .
04 1 0
04 2 .
04 3 .
04 4 .I'm not sure what I'm doing wrong, please help!!!
Please closely examine the names of the variables highlighted.
An array statement will create new variables if the name referenced on the array statement does not already exist.
You used three variable names on the array statement that were not already in the input data set.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.