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

Hello All, I need help debugging and understanding errors in my code.

 

What I want is a permanent dataset named Data.ChiSqResults that looks like this:

 

Test                DF   Value   P-Value

Chi-Square     2     1.71     0.43

 

What I start with: See picture ~"Statistics for Table of Death BY State"

But I run my code I get two warnings and an empty dataset. For some Reason, my Ods Output isn't saving to my Work Library and I don't know why. I tried changing locations to the folder Library.Heartattack but that didn't work either.

I tried closing my SAS and that didn't help either. 

I was able to get ODS OUTPUT to work one time but I don't know how I did that and it seemed like a goof as it didn't rerun. But even when it did run, I got an empty table (See last picture) as it didn't seem to recognize my IF statement. In addition, I also recieved the sporadic warning: "WARNING: Duplicate data set name on ODS OUTPUT statement. Entry will be ignored." and I don't know what triggers it.

 

TODO:

  • Isolate the "Chi-Square" Observation in a new Permanent Dataset (HIGHEST PRIORITY)
  • Round the Value and Probability to 2 decimal places without trailing zeroes.

 

 

CODE

* Step 2: Perform a Chi-Square Test and Save the Results *; RUN;
ODS TRACE ON;
PROC FREQ DATA = heartattack.ANALYSIS2;
TABLES Death * STATE /CHISQ NOROW NOPERCENT;
RUN;
ODS TRACE OFF;

ODS OUTPUT CROSSTABFREQS = WORK.STATES
CHISQ = WORK.CHISQRESULTS;

/* ODS OUTPUT CROSSTABFREQS = Heartattack.CROSSTABFREQS */
/* CHISQ = heartattack.CHISQ; */

DATA WORK.CHISQRESULTS;
SET Heartattack.CHISQRESULTS;
KEEP STATISTIC DF VALUE PROB;
LABEL PROB = "P-VALUE";
IF STATISITIC = "Chi-Square";
VALUE = ROUND(VALUE, 0.01);
PROB = ROUND(PROB, 0.01);
RUN;

PROC PRINT DATA = Heartattack.CHISQRESULTS NOOBS;
RUN;

LOG

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
NOTE: ODS statements in the SAS Studio environment may disable some output features.
73
74 ODS TRACE ON;
75 PROC FREQ DATA = Heartattack.HYPANALYSIS2;
76 TABLES HYPRELDEATHIND * STATECD /CHISQ NOROW NOPERCENT;
77 RUN;
 
 
Output Added:
-------------
Name: CrossTabFreqs
Label: Cross-Tabular Freq Table
Template: Base.Freq.CrossTabFreqs
Path: Freq.Table1.CrossTabFreqs
-------------
 
Output Added:
-------------
Name: ChiSq
Label: Chi-Square Tests
Template: Base.Freq.ChiSq
Path: Freq.Table1.ChiSq
-------------
NOTE: There were 573 observations read from the data set heartattack.HYPANALYSIS2.
NOTE: PROCEDURE FREQ used (Total process time):
real time 0.89 seconds
cpu time 0.67 seconds
 
 
78 ODS TRACE OFF;
79
80 ODS OUTPUT CROSSTABFREQS = WORK.STATEPERCENTS
81 CHISQ = WORK.CHISQRESULTS;
82
83 /* ODS OUTPUT CROSSTABFREQS = HYPRSLT.CROSSTABFREQS */
84 /* CHISQ = Heartattack.CHISQ; */
85
86 DATA WORK.CHISQRESULTS;
87 SET Heartattack.CHISQRESULTS;
88 KEEP STATISTIC DF VALUE PROB;
89 LABEL PROB = "P-VALUE";
90 IF STATISITIC = "Chi-Square";
91 VALUE = ROUND(VALUE, 0.01);
92 PROB = ROUND(PROB, 0.01);
93 RUN;
 
NOTE: Variable STATISITIC is uninitialized.
NOTE: There were 6 observations read from the data set Heartattack.CHISQRESULTS.
NOTE: The data set WORK.CHISQRESULTS has 0 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time 0.19 seconds
cpu time 0.17 seconds
 
 
94
95 PROC PRINT DATA = Heartattack.CHISQRESULTS NOOBS;
96 RUN;
 
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.
WARNING: Output 'CROSSTABFREQS' 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.
NOTE: There were 6 observations read from the data set Heartattack.CHISQRESULTS.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.40 seconds
cpu time 0.34 seconds
 
 
97
98
99 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
111
 
SCREENSHOTS
 

Screen Shot 2020-12-01 at 10.12.26 PM.pngScreen Shot 2020-12-01 at 10.23.32 PM.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Deanna_Payne
Obsidian | Level 7

Thankyou everyone for your help!

 

I was able to fix it with your advice and this is the solution I settled on...

 

Best, 

Deanna

 

***;

ODS OUTPUT CROSSTABFREQS = WORK.STATEPERCENTS
CHISQ = WORK.CHISQRESULTS;

ODS TRACE ON;
PROC FREQ DATA = Heartattack.ANALYSIS2;
TABLES HYPRELDEATHIND * STATECD /CHISQ NOROW NOPERCENT;
RUN;
ODS TRACE OFF;


DATA WORK.CHISQRESULTS;
SET Heartattack.CHISQRESULTS;
KEEP STATISTIC DF VALUE PROB;
LABEL PROB = "P-VALUE";
IF STATISTIC = "Chi-Square";
VALUE = ROUND(VALUE, 0.01);
PROB = ROUND(PROB, 0.01);
FORMAT VALUE F12.2
PROB F12.2;

RUN;

PROC PRINT DATA = WORK.CHISQRESULTS NOOBS;
RUN;

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User

This

NOTE: Variable STATISITIC is uninitialized.

is your most important clue. Basically, you never want to see that NOTE in your log, as it alerts you either to a mis-typed variable name or a variable that you somehow create (e.g. in a FORMAT statement), but never use. Such NOTEs need to be cleaned up, see Maxim 25.

In your case, it is a typo, as the variable is called statistic, not statisitic.

Cynthia_sas
SAS Super FREQ
And, to build on this comment in particular, the ODS OUTPUT statement usually is placed BEFORE your procedure call, not AFTER -- as:
ODS OUTPUT <for PROC FREQ step>;
PROC FREQ data=xxx;
run;

ODS OUTPUT <for PROC MEANS step>;
PROC MEANS data=xxx;
run;

Cynthia
ballardw
Super User

Your log shows:

86 DATA WORK.CHISQRESULTS;
87 SET HYPRSLT.CHISQRESULTS;

The ODS output

ODS OUTPUT CROSSTABFREQS = WORK.STATEPERCENTS
CHISQ = WORK.CHISQRESULTS;

Does that help?

 

 

Be aware that using the same data set for input (Set statement) and output (Data statement) replaces the input data set if there are no serious errors. So you may destroy the data you need. Until more familiar with SAS I strongly recommend not using the coding structure:

data somedatesetname;   
    set somedatesetname;
Deanna_Payne
Obsidian | Level 7

Thankyou everyone for your help!

 

I was able to fix it with your advice and this is the solution I settled on...

 

Best, 

Deanna

 

***;

ODS OUTPUT CROSSTABFREQS = WORK.STATEPERCENTS
CHISQ = WORK.CHISQRESULTS;

ODS TRACE ON;
PROC FREQ DATA = Heartattack.ANALYSIS2;
TABLES HYPRELDEATHIND * STATECD /CHISQ NOROW NOPERCENT;
RUN;
ODS TRACE OFF;


DATA WORK.CHISQRESULTS;
SET Heartattack.CHISQRESULTS;
KEEP STATISTIC DF VALUE PROB;
LABEL PROB = "P-VALUE";
IF STATISTIC = "Chi-Square";
VALUE = ROUND(VALUE, 0.01);
PROB = ROUND(PROB, 0.01);
FORMAT VALUE F12.2
PROB F12.2;

RUN;

PROC PRINT DATA = WORK.CHISQRESULTS NOOBS;
RUN;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 7265 views
  • 4 likes
  • 4 in conversation