BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ertr
Quartz | Level 8

 

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

1 ACCEPTED SOLUTION

Accepted Solutions
2 REPLIES 2
Reeza
Super User

Take a substring and compare that. 

 

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

Astounding
PROC Star

A small change is all that is required:

 

if variable in : (&macro.);

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 2 replies
  • 763 views
  • 3 likes
  • 3 in conversation