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

Hi,

 

suppose I have the variable diff and 5 other variables (among many others) a,b,c,d,e.

 

Whenever the diff = '' I want also the other 5 variabels also be =''.

 

I did the following code:

 

data have;
set have;
array variables[5] 
a b c d e;
if diff = '' then
do i = 1 to 5
 variables[i]= '';
end;
drop i ;
run;

But get errors... I guess that the logic of my syntax isn't correct, although I tried to do some modifications of the code and still get errors. Could you please help me?

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
set have;
array variables[5] a b c d e;

if diff ='' then call missing(of variables[*]);

run;

View solution in original post

4 REPLIES 4
ilikesas
Barite | Level 11

I think I got it: I should have put the if statement inside the do statament:

 

data have;
set have;
array variables[5]
a b c d e;
do i = 1 to 5;
if diff ='' then variables[i] = '';
end;
drop i;
run;

But if there is a better way I will be very happy to learn!!!

Reeza
Super User

CALL MISSING()

http://support.sas.com/documentation/cdl/en/lefunctionsref/67960/HTML/default/viewer.htm#p1iq436yh88...

 

This code doesn't care if diff and variables are character or numeric.

if missing(diff) then call missing(of variables(*));

 

 

Ksharp
Super User
data have;
set have;
array variables[5] a b c d e;

if diff ='' then call missing(of variables[*]);

run;
Astounding
PROC Star

While you have some valid suggestions here, your original problem was a missing semicolon:

 

1 to 5 ;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 2046 views
  • 8 likes
  • 4 in conversation