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

Hello,

I would like to filter the below data produced by Proc Freq between dates. My where statement below isn't working. Help

 

Title 'BSC Member_Bis Counts';
proc freq data=&Project..enrollment_bis_final_collapsed;
format mctr_based_prod_id $Product.;
ods output onewayfreqs=BSC_Enrollment_Count;
tables mctr_based_prod_id;
WHERE t1.TerminationDate BETWEEN &Term_st. AND &Term_ed.;
run;
Title;

1 ACCEPTED SOLUTION

Accepted Solutions
tom_grant
SAS Super FREQ
Assuming all your macro vars are set & you've defined your format $Product, looks like you are using SQL syntax for your where statement - you do not need the t1. if TerminationDate is in your data set &Project..enrollment_bis_final_collapsed.

View solution in original post

5 REPLIES 5
mkeintz
PROC Star

Using "isn't working" as your total description of a problem just .. "doesn't work".

 

What did you get vs what you expected?  Were there any error message on your sas log?  What does the log report?

 

If the log provided no error messages, what erroneous output did the PROC FREQ produce?

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
tom_grant
SAS Super FREQ
Assuming all your macro vars are set & you've defined your format $Product, looks like you are using SQL syntax for your where statement - you do not need the t1. if TerminationDate is in your data set &Project..enrollment_bis_final_collapsed.
Jesusismygrace
Obsidian | Level 7
Perfect! Thank you
ballardw
Super User

@Jesusismygrace wrote:

Hello,

I would like to filter the below data produced by Proc Freq between dates. My where statement below isn't working. Help

 

Title 'BSC Member_Bis Counts';
proc freq data=&Project..enrollment_bis_final_collapsed;
format mctr_based_prod_id $Product.;
ods output onewayfreqs=BSC_Enrollment_Count;
tables mctr_based_prod_id;
WHERE t1.TerminationDate BETWEEN &Term_st. AND &Term_ed.;
run;
Title;


If TerminationDate is a variable in &Project..enrollment_bis_final_collapsed then you do not use T1. notation. You should show your log with the error and the code and paste into a text box opened on the forum with the </> icon. 

Since you do not show assignments for ANY of the macro variables can't tell if they are appropriate or not.

 

Such as :

272  proc freq data=sashelp.class;
273     where t1.sex in ('F' 'M');
              ------
              180
ERROR: Syntax error while parsing WHERE clause.
ERROR 180-322: Statement is not valid or it is used out of proper order.
274  run;

Dot notation in the middle of a procedure except in very few cases is right out. You would be wrong to include any reference to a data set as once you have a data set on the Proc statement that is the source of all variables.

 

Jesusismygrace
Obsidian | Level 7
Thank you, Got it

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 928 views
  • 3 likes
  • 4 in conversation