BookmarkSubscribeRSS Feed
Baba9
Obsidian | Level 7

Can I write two different variable names in the array as shown below if not how would i change the code below?

array diag{*} MAIN_PROBLEM OTHER_PROBLEM_:;
		do i = 1 to dim(diag);
		if diag{i} in ('L400' 'L401' 'L403' 'L409') then gpp = 1;
		if diag{i} in: ('O04' 'O07' 'P964') then TA = 1;
	end;

	/* exclude TA */
	array interv{*} MAIN_INTERVENTION OTHER_INTERVENTION_:
	   do j=1 to dim(interv);
	      if interv{j} in: ('5CA20' '5CA24' '5CA88' '5CA89' '5CA90') then TA = 1;
	end;

names in the array?

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Did you actually try running the code? What happened? If there is an error show us the ENTIRE log (that's 100% of the log, every single character, in the order it appears, do not chop out parts) for this DATA step.

--
Paige Miller
ballardw
Super User

To recommend changes we would have to know what the input looks like and the desired output.

 

Arrays can have a lot of different variables as long as they are of the same type, numeric or character.

FreelanceReinh
Jade | Level 19

Hello @Baba9,


@Baba9 wrote:

Can I write two different variable names in the array as shown below ...

...
	array interv{*} MAIN_INTERVENTION OTHER_INTERVENTION_:;
...

Yes, your code is syntactically correct, except for the missing semicolon after the second ARRAY statement.

Tom
Super User Tom
Super User

What is the question exactly.

Yes you can type as many variables names into an ARRAY statement as you want.

If you use the : wildcard to specify the names by their prefix then the variables have a to already exist in the data step.

But if you list them explicitly and those names do not already exist they will be created.

So a statement like:

array diag MAIN_PROBLEM OTHER_PROBLEM_:;

Will define the array DIAG with one or more variables, depending on how many existing variables have names that start with OTHER_PROBLEM_.

Baba9
Obsidian | Level 7

Thankyou All

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 5 replies
  • 1008 views
  • 5 likes
  • 5 in conversation