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

Hi,

 

Are there any resources regarding when to do a do loop with an array, as opposed to just a do loop without an array? What are the advantages of using an array, and when use them?

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

ARRAYs are usually useful when you want to perform the same (or very similar) analysis on many different columns.

 

Do loops not in an array are much more general, and allow you to iterate until some (hopefully) desirable result is obtained.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

ARRAYs are usually useful when you want to perform the same (or very similar) analysis on many different columns.

 

Do loops not in an array are much more general, and allow you to iterate until some (hopefully) desirable result is obtained.

--
Paige Miller
ManitobaMoose
Quartz | Level 8

Thanks.

 

I also have one other related question: the _n_ = 1 for arrays. Does that mean it starts at the first observation, first line. etc? I see that written and I am not entirely sure what it does. See the code below.

 

Data score ; 
	array ans{10} $1 ; 
	array key{10} $1 _temporary_  ; 
*Load the temporary array elements*
	If _n_ = 1 then do Ques = 1 to 10 ; *_n_ = 1 only does first line of the key *
I		input key{Ques} $1. @ ; 
	end ; 
	
	Input ID (Ans1-Ans10) ($1.) ;
	Rawscore = 0 ; 
	
*Score the Test*
	do Ques = 1 to 10 ; 
		Rawscore + (key(Ques) eq Ans(Ques)) ; 
	end ; 
Percent = 100*Rawscore ; 
keep ID Rawscore Percent ; 
Datalines ; 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1257 views
  • 0 likes
  • 2 in conversation