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

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
Fluorite | Level 6

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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 484 views
  • 5 likes
  • 4 in conversation