My code is below. My approach is clunky at best. I submit it, see if there is an error, adjust the code and resubmit. How can I edit it so that SAS determines the dimensions needed?
data coregrades;
set core2;
format mark1-mark5 $3. course_name1-course_name5 $8. name1-name5 $30. point1-point5 1. course_number1-course_number5 $8.;
by student_number;
retain name1-name5 course_name1-course_name5 mark1-mark5 point1-point5 course_number1-course_number5;
if first.student_number then do;
name1=' '; name2=' '; name3=' '; name4=' '; name5=' ';
course_name1=' '; course_name2=' '; course_name3=' '; course_name4=' '; course_name5=' ';
mark1=' '; mark2=' '; mark3=' '; mark4=' '; mark5=' ';
point1=.; point2=.; point3=.; point4=.; point5=.;
course_number1=' ';course_number2=' ';course_number3=' ';course_number4=' ';course_number5=' ';
markcount=1;
end;
array names {5} name1-name5;
array course_names {5} course_name1-course_name5;
array marks {5} mark1-mark5;
array points {5} point1-point5;
array course_numbers {5} course_number1-course_number5;
names {markcount} = name;
course_names {markcount} = course_name;
marks {markcount} = mark;
points {markcount} = point;
course_numbers {markcount} = course_number;
markcount+1;
drop name course_name mark point course_number;
if last.student_number;
run;
Determine the needed array size by running:
proc sql;
create table int as
select count(*) as count from core2 group by student_number;
select max(count) from int;
quit;
Hi,
you could use the colon wildcard.
data test; name1=1; name2=2; name3=3; name4=4; name5=5; output; run; data test; set test; array names name:; do over names; names=names+1; put names; end; run;
- Cheers -
Determine the needed array size by running:
proc sql;
create table int as
select count(*) as count from core2 group by student_number;
select max(count) from int;
quit;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: