- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Great suggestion!
Thanks to everyone!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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