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:
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
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;
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.
And PROC PRINT will never create an output called chisq or crosstabfreqs.
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;
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;
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!
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.