BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Curt
Obsidian | Level 7

Hi everyone,

 

I got an unexpected error when I tried to run:

 

WHERE prxmatch('/prx-pattern/', catx(' ', of charvar1-charvar100))

 

instead of

 

IF prxmatch('/prx-pattern/', catx(' ', of charvar1-charvar100)) 

 

where no error occurs.

 

If I write "charvar1, charvar2, charvar3 ..."  instead of  "OF charvar1-charvar100" the program is running without errors, but I wonder why this error occurs anyway and how can I sum up the variables like when using the IF statement, so that I don't need to enumerate all 100 variables.

 

Many thanks in advance,

Curt

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @Curt,

 

You are not the first who encounters the fact that the OF operator is not available in WHERE statements and WHERE= dataset options (see, e.g., this 2021 thread). I think the documentation (like the second link provided by PaigeMiller) should mention this more clearly.

 

In your case you could create a DATA step view using the IF statement and then apply PROC FREQ to that view.

 

Example:

data sel / view=sel;
set sashelp.us_data;
if max(of change:)>20;
run;

proc freq data=sel;
tables region;
run;

View solution in original post

5 REPLIES 5
Curt
Obsidian | Level 7

Thanks for your reply.

 

I know that it would be better to use the IF STATEMENT instead of the WHERE STATEMENT, however, I want to do  PROC FREQ where listed variables have one of the listed values. So it is not possible to use the IF STATEMENT instead. 

FreelanceReinh
Jade | Level 19

Hi @Curt,

 

You are not the first who encounters the fact that the OF operator is not available in WHERE statements and WHERE= dataset options (see, e.g., this 2021 thread). I think the documentation (like the second link provided by PaigeMiller) should mention this more clearly.

 

In your case you could create a DATA step view using the IF statement and then apply PROC FREQ to that view.

 

Example:

data sel / view=sel;
set sashelp.us_data;
if max(of change:)>20;
run;

proc freq data=sel;
tables region;
run;
yabwon
Onyx | Level 15

The "charvar1-charvar100" is one type of SAS variables lists (to be precise: Numbered Range Lists). 

Documentation:

SAS Variables Lists:

https://documentation.sas.com/doc/en/lrcon/9.4/p0wphcpsfgx6o7n1sjtqzizp1n39.htm

OF operator with SVL:

https://documentation.sas.com/doc/en/lrcon/9.4/n1t04bwpt1jkadn1a5mk35we2yif.htm

 

SAS variables list are PDV construct, i.e. they are available _only_ in/for the PDV vector.

And as the second link provided by @PaigeMiller (https://documentation.sas.com/doc/en/lrcon/9.4/p04fy20d8il3nfn1ssywe4f25k27.htm) says:

"A WHERE expression tests the condition before an observation is read into the PDV."

So, since WHERE works "before" PDV - there is no chance to use PDV's constructs...

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 5 replies
  • 1104 views
  • 5 likes
  • 4 in conversation