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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 1033 views
  • 8 likes
  • 4 in conversation