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

Hi there. I am attempting to create a data set using the ODS OUTPUT and PROC FREQ statements. My goal is to only display the Chi-Square observation for the data. 

 

I first ran ODS trace to find the name of the table I want:

 

ODS TRACE ON;
PROC FREQ DATA = WORK.data ;
	TABLES var1* var2/ CHISQ ;
	RUN;
ODS TRACE OFF;

Next, I created the data set with PROC FREQ:

 

ODS OUTPUT	ChiSq = WORK.data2;
PROC FREQ DATA = WORK.data;
	TABLES	var1* var2/	NOCUM NOROW NOPERCENT NOCOL CHISQ;
/*	WHERE Statistic = 'Chi-Square' ;*/
	RUN;

=> as you can see, I tried using the WHERE syntax to keep only the Chi-Square observation, but this is the warning I receive in the log (see below). My goal is to have a data set with just Obs-1, Statistic = Chi-Square. Not sure what I'm doing incorrectly. Thank you!

305  ODS OUTPUT  ChiSq = WORK.data2;
306  PROC FREQ DATA = WORK.data ;
307      TABLES  var1 * var2/  NOCUM NOROW NOPERCENT NOCOL CHISQ;
308      WHERE Statistic = 'Chi-Square' ;
ERROR: Variable Statistic is not on file WORK.data.
309      RUN;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE FREQ used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

WARNING: Output 'ChiSq' was not created.  Make sure that the output object name, label, or path is
         spelled correctly.  Also, verify that the appropriate procedure options are used to produce
         the requested output object.  For example, verify that the NOPRINT option is not used.

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @lsandell,

 

WHERE statements refer to the input dataset, which is WORK.HypAnalysis2 in your PROC FREQ step. To restrict the ODS output dataset to the observation satisfying the WHERE condition, use that condition in a WHERE= dataset option in parentheses after WORK.ChiSqResults:

ODS OUTPUT ChiSq = WORK.ChiSqResults(where=(Statistic = 'Chi-Square'));

View solution in original post

1 REPLY 1
FreelanceReinh
Jade | Level 19

Hi @lsandell,

 

WHERE statements refer to the input dataset, which is WORK.HypAnalysis2 in your PROC FREQ step. To restrict the ODS output dataset to the observation satisfying the WHERE condition, use that condition in a WHERE= dataset option in parentheses after WORK.ChiSqResults:

ODS OUTPUT ChiSq = WORK.ChiSqResults(where=(Statistic = 'Chi-Square'));

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
  • 1 reply
  • 2506 views
  • 4 likes
  • 2 in conversation