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

Listing variables with common prefix supposed to work with "P0701--P0703"  I thought. But it doesn't run when put it in the below context.

Any suggestions?

 

 

data want; set have;
array m Code_1-Code_24; 
do over m;
if m in ("P0701","P0702","P0703","P0714","P0715","P0716", "P0717","P0718") then b=1; else 
if m in ("P0721","P0722","P0723","P0724","P0725","P0726", "P0731","P0732","P0733","P0734","P0735","P0736","P0737","P0738","P0739") then b=2; else   
if m in ("P07","P070","P071","P0710","P072","P073","P0730") then b=3; else    
if m in ("P0700","P0720") then b=4;     
end; 
run;

Thank you.

 

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Not sure what you're asking. Both of the following will satisfy your example:

data want;
  set have;
  array m $ Code_1-Code_24; 
  do over m;
    if m in ("P0701","P0702","P0703","P0714","P0715","P0716", "P0717","P0718") then b=1;
    else if m in ("P0721","P0722","P0723","P0724","P0725","P0726", "P0731","P0732","P0733","P0734","P0735","P0736","P0737","P0738","P0739") then b=2;
    else if m in ("P07","P070","P071","P0710","P072","P073","P0730") then b=3;
    else if m in ("P0700","P0720") then b=4;     
  end; 
run;

data want;
  set have;
  array m $ Code_1-Code_24; 
  do over m;
    if "P0701" le m le "P0718" then b=1;
    else if "P0721" le m le "P0739" then b=2;
    else if m in ("P07","P070","P071","P0710","P072","P073","P0730") then b=3;
    else if m in ("P0700","P0720") then b=4;     
  end; 
run;

Art, CEO, AnalystFinder.com

View solution in original post

2 REPLIES 2
WarrenKuhfeld
Ammonite | Level 13

Those are character strings not variables. This will work for one of your statements.

 

if m in (%macro m; %do i = 701 %to 703; "P0&i" %end; %do i = 714 %to 718; "P0&i" %end; %mend;%m) then b=1;

art297
Opal | Level 21

Not sure what you're asking. Both of the following will satisfy your example:

data want;
  set have;
  array m $ Code_1-Code_24; 
  do over m;
    if m in ("P0701","P0702","P0703","P0714","P0715","P0716", "P0717","P0718") then b=1;
    else if m in ("P0721","P0722","P0723","P0724","P0725","P0726", "P0731","P0732","P0733","P0734","P0735","P0736","P0737","P0738","P0739") then b=2;
    else if m in ("P07","P070","P071","P0710","P072","P073","P0730") then b=3;
    else if m in ("P0700","P0720") then b=4;     
  end; 
run;

data want;
  set have;
  array m $ Code_1-Code_24; 
  do over m;
    if "P0701" le m le "P0718" then b=1;
    else if "P0721" le m le "P0739" then b=2;
    else if m in ("P07","P070","P071","P0710","P072","P073","P0730") then b=3;
    else if m in ("P0700","P0720") then b=4;     
  end; 
run;

Art, CEO, AnalystFinder.com

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2031 views
  • 1 like
  • 3 in conversation