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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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;

View solution in original post

2 REPLIES 2
Oligolas
Barite | Level 11

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 -

Kurt_Bremser
Super User

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 942 views
  • 0 likes
  • 3 in conversation