DATA Step, Macro, Functions and more

deleting variable values based on another variable value

Accepted Solution Solved
Reply
Super Contributor
Posts: 441
Accepted Solution

deleting variable values based on another variable value

[ Edited ]

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!


Accepted Solutions
Solution
‎10-25-2016 11:15 PM
Super User
Posts: 10,047

Re: deleting variable values based on another variable value

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


All Replies
Super Contributor
Posts: 441

Re: deleting variable values based on another variable value

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!!!

Super User
Posts: 19,878

Re: deleting variable values based on another variable value

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(*));

 

 

Solution
‎10-25-2016 11:15 PM
Super User
Posts: 10,047

Re: deleting variable values based on another variable value

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

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

run;
Super User
Posts: 5,518

Re: deleting variable values based on another variable value

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

 

1 to 5 ;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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