DATA Step, Macro, Functions and more

different variables for the if statement same then.

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 19
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,117

Re: different variables for the if statement same then.

Posted in reply to sasiscool

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,117

Re: different variables for the if statement same then.

Posted in reply to sasiscool

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: 19

Re: different variables for the if statement same then.

Posted in reply to FreelanceReinhard

great thank you.

Super User
Posts: 11,343

Re: different variables for the if statement same then.

Posted in reply to sasiscool

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
  • 229 views
  • 0 likes
  • 3 in conversation