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

I have character variables pt1-pt&review (the maximum ranges vary).  I'm trying to find out if there is a match to main variable allpt for each of these variables by using index function for all the rows (first.id to last.id) in the dataset. If matched, the array variables check1-check&review will have value>0.    Since I need to use the value of the variables pt1-pt34 for index function, I tried using macro function "call symputx..."  I'm getting error messages with the codes below.

 

data tagged;
length id $ 8 check1-check&review 8;
do until (last.id);
set case;
by id;
array pt(&review) $;
array check(&review) $;
do i = 1 to dim(check);
call symputx ('name', pt[i]);
check[i] = index (allpt,'&name');
end;
drop i;
run;

 

ERROR 22-322: Syntax error, expecting one of the following: a name, _ALL_, _CHARACTER_, _CHAR_,
_NUMERIC_.

ERROR: Missing numeric suffix on a numbered variable list (check1-check).
ERROR 352-185: The length of numeric variables is 3-8.

 

Macro variable REVIEW resolved successfully, by the way.

 

Thanks for help!

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

This

call symputx ('name', pt[i]);
check[i] = index (PTUPC,'&name');

cannot work, for two reasons:

  1. macro triggers are not resolved when enclosed in single quotes, one must use double quotes.
  2. but the more important: the macro reference will be resolved while the data step is compiled, but call symput() is executed when the data step runs.

Why don't you just do

check[i] = index(PTUPC,strip(pt[i]));

?

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User

If macro variable &review has leading blanks, it won't work.

Either change how you set it, or add

%let review=&review.;

to remove the blanks.

Tom
Super User Tom
Super User

How did you create the macro variable REVIEW?

If you are using PROC SQL with the INTO clause then make sure to use the TRIMMED keyword to remove leading spaces.

proc sql noprint;
select max(review_number) into :review TRIMMED 
from mydata;
quit;

You could also use %LET to remove unquoted spaces.

%let review=&review ;

Or modify your program so that leading spaces don't impact it.  For example set the length of CHECK1 to CHECK8 using the ARRAY statement.  Also make you your mind whether CHECK1 to CHECK8 are numeric or character.  Your LENGTH statement defines them as numeric put you included a $ in your array statement.  Assuming you want them as character:

data tagged;
  length id $8 ;
  array check(&review) $8;
sonic_poem
Calcite | Level 5

Thanks for the feed back.  I tried the methods suggested.  I also tried using numeric version of review (as reviewn) to see if it helps.

proc sql;

select count as observation

into: review TRIMMED

from high;

quit;

%let review=&review;

%let reviewn=%eval(&review);

 

Good thing is using either REVIEW or REVIEWN, I no longer get any error messages.  However, all my CHECK variables are 0 using the program below.  I believe CHECK should be a numeric variable since it's an output from the INDEX function.  I have modified the code as suggested.  I am also uploading the sample data and the output I would like to see when the program runs successfully.

 

proc sort data=case3;by id;run;

data tagged;

length id $ 8 check1-check&review 8;

do until (last.id);

set case3;

by id;

array pt(&review) $;

array check(&review) ;

do i = 1 to dim(check);

call symputx ('name', pt[i]);

check[i] = index (PTUPC,'&name');

end;

end;

drop i;

run;

 

 

idpt1pt2pt3allpt ck1 ck2ck3
a001ababacabd110
a002acabdcabd010
a003adabbdabd012
Kurt_Bremser
Super User

This

call symputx ('name', pt[i]);
check[i] = index (PTUPC,'&name');

cannot work, for two reasons:

  1. macro triggers are not resolved when enclosed in single quotes, one must use double quotes.
  2. but the more important: the macro reference will be resolved while the data step is compiled, but call symput() is executed when the data step runs.

Why don't you just do

check[i] = index(PTUPC,strip(pt[i]));

?

sonic_poem
Calcite | Level 5

The corrected version below is working. Thank you!  

 

data tagged;

length id $ 8 check1-check&reviewn 8;

do until (last.id);

set case3;

by id;

array pt(&reviewn) $;

array check(&reviewn) ;

do i = 1 to dim(check);

check[i] = index(PTUPC,strip(pt[i]));

end;

end;

drop i;

run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 5 replies
  • 2760 views
  • 0 likes
  • 3 in conversation