DATA Step, Macro, Functions and more

different variables for the if statement same then.

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 16
Accepted Solution

different variables for the if statement same then.

I have multiple variables that follow in sequential order ques5-ques20. Each of these varibles have some entries with a "*" that I want to change to a blank.

 

Rather than write out a ton of if-or-then. (if ques5="*" then ques5=" ")....

 

How can i achieve this more efficiently with a do loop?

 

Thank you!


Accepted Solutions
Solution
‎04-28-2016 01:52 PM
Trusted Advisor
Posts: 1,115

Re: different variables for the if statement same then.

Hi @sasiscool,

 

Try this:

data want;
set have;
array q ques5-ques20;
do _n_=1 to dim(q);
  if strip(q[_n_])='*' then q[_n_]=' ';
end;
run;

View solution in original post


All Replies
Solution
‎04-28-2016 01:52 PM
Trusted Advisor
Posts: 1,115

Re: different variables for the if statement same then.

Hi @sasiscool,

 

Try this:

data want;
set have;
array q ques5-ques20;
do _n_=1 to dim(q);
  if strip(q[_n_])='*' then q[_n_]=' ';
end;
run;
Occasional Contributor
Posts: 16

Re: different variables for the if statement same then.

great thank you.

Super User
Posts: 10,500

Re: different variables for the if statement same then.

Please mark the appropriate solution as accepted.

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 224 views
  • 0 likes
  • 3 in conversation