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
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;
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.
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;
Great suggestion!
Thanks to everyone!
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
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.
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.
Ready to level-up your skills? Choose your own adventure.