DATA Step, Macro, Functions and more

How to - Get Specified Values By Taking Specified Digits From Variables Values - For Macro Variables

Accepted Solution Solved
Reply
Contributor
Posts: 59
Accepted Solution

How to - Get Specified Values By Taking Specified Digits From Variables Values - For Macro Variables

[ Edited ]

 

Hello,

 

I want to get following "Variable" column's first three digits.

I define the first three digits i.e:"WOE", "REP". If I use "=:" option then I write first three digits, it brings my desired values but what if I have more than one value. Sometimes, I need 5 or 6 values i.e:"WOE","REP","IMP","ITA","BEL" etc. so I want to put these values into macro variable then use into my code.

 

I hope I could make myself clear. Can you help me about to reach my aim, please?

 

Data Have;
Do i=1 to 5;
Variable="WOE_Hart";
Output;
End;
Do i=1 to 5;
Variable="REP_Buff";
Output;
End;
Do i=1 to 5;
Variable="IMP_Steph";
Output;
End;
Run;
 
Data Want2;
Set Have;
If Variable=:"REP" Or Variable =:"IMP" Or Variable=:"ASK ";
Run;

%Let Macro= "WOE" "REP"; 

Data Want3;
Set Have;
If Variable =:(&Macro.);
Run;

Thank you


Accepted Solutions
Solution
‎06-28-2016 12:14 PM
Super User
Posts: 5,496

Re: How to - Get Specified Values By Taking Specified Digits From Variables Values - For Macro Varia

A small change is all that is required:

 

if variable in : (&macro.);

View solution in original post


All Replies
Super User
Posts: 19,768

Re: How to - Get Specified Values By Taking Specified Digits From Variables Values - For Macro Varia

Take a substring and compare that. 

 

If substr(variable, 1,3) in ('REP', ...,'ASK') then ...

Solution
‎06-28-2016 12:14 PM
Super User
Posts: 5,496

Re: How to - Get Specified Values By Taking Specified Digits From Variables Values - For Macro Varia

A small change is all that is required:

 

if variable in : (&macro.);

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 187 views
  • 3 likes
  • 3 in conversation