- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
I am trying to control the number of decimals reported in an ODS output (I want Value and Prob to appear with two decimals as opposed to 4). I tried using a FORMAT statement in the PROC FREQ, but it said those variables are not recognized. Any help would be appreciated, thank you!
ODS OUTPUT ChiSq = ChiSqResults ( KEEP = Statistic DF Value Prob
WHERE = (Statistic = 'Chi-Square'));
PROC FREQ
DATA = Have;
TABLES HTNDeath * State / CHISQ NOPERCENT NOROW;
RUN;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@efboggs wrote:
Hi all,
I am trying to control the number of decimals reported in an ODS output (I want Value and Prob to appear with two decimals as opposed to 4). I tried using a FORMAT statement in the PROC FREQ, but it said those variables are not recognized. Any help would be appreciated, thank you!
ODS OUTPUT ChiSq = HypRslt.ChiSqResults ( KEEP = Statistic DF Value Prob
WHERE = (Statistic = 'Chi-Square'));
PROC FREQ
DATA = HypAnl.HypAnalysis2;
TABLES HypRelDeathInd * StateCd / CHISQ NOPERCENT NOROW;
RUN;
PROC PRINT DATA = HypRslt.ChiSqResults; RUN;
PROC CONTENTS DATA = HypRslt.ChiSqResults; RUN;
Any time you get an error, such as "those variables are not recognized" post the LOG with the messages in question. Copy from the LOG and paste into a code box opened on the forum with the </> to preserve the formatting of the diagnostic text that SAS often provides with errors.
A common cause of this message is not ending a format name with the . character. If you don't then then SAS thinks you are listing a variable.
Since NONE of your code shows any attempt to use a format then we have no idea what you attempted regarding the format.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Apologies @ballardw, here is my code attempting to apply a format-
ODS OUTPUT ChiSq = ChiSqResults ( KEEP = Statistic DF Value Prob
WHERE = (Statistic = 'Chi-Square'));
PROC FREQ
DATA = HTN;
TABLES HTNDeath * State / CHISQ NOPERCENT NOROW;
FORMAT Value 4.2;
FORMAT Prob 5.2;
RUN;
Here is the log:
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@efboggs wrote:
Apologies @ballardw, here is my code attempting to apply a format-
ODS OUTPUT ChiSq = HypRslt.ChiSqResults ( KEEP = Statistic DF Value Prob
WHERE = (Statistic = 'Chi-Square'));PROC FREQ
DATA = HypAnl.HypAnalysis2;
TABLES HypRelDeathInd * StateCd / CHISQ NOPERCENT NOROW;
FORMAT Value 4.2;
FORMAT Prob 5.2;
RUN;
Here is the log:
NOTE: ODS statements in the SAS Studio environment may disable some output features.737475 ODS OUTPUT ChiSq = HypRslt.ChiSqResults (KEEP= Statistic DF Value Prob76 WHERE= (Statistic = 'Chi-Square'));77 PROC FREQ78 DATA = HypAnl.HypAnalysis2;79 TABLESHypRelDeathInd * StateCd / CHISQ NOPERCENT NOROW;80 FORMAT Value 4.2;WARNING: Variable VALUE not found in data set HYPANL.HYPANALYSIS2.81 FORMAT Prob 5.2;WARNING: Variable PROB not found in data set HYPANL.HYPANALYSIS2.82 RUN;
What is happening here, and will in a great many procedures is that the Syntax in the body of the procedure only applies to variables in the INPUT data set. The variables with the warnings are created by the ODS OUTPUT and the behind the scenes things that go on set the format, not your code at this time. Post processing to associate the formats with the specific output data set variables, or use of appropriate format an a different procedure that displays the values, such as Proc Print, Report or graphing procedure, is when the format would be used.
Some of the modeling procedures potentially produce over 20 ODS tables, some with similar named variables (Statistic is common) but may need different formats to be usable. So the procedures don't let you override the default template set formats in procedure code. Once the output is created then you can override as several examples show.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hey there! It is a lot easier to use the DEFINE statement in the PROC REPORT step to format everything that way you want it. Here is what I did:
PROC REPORT DATA=Source;DEFINE Prob / "P-Value" FORMAT= 5.2;
DEFINE Value / FORMAT= 4.2;
RUN;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Ah thank you, that is super helpful!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Add a small post-processing step:
proc sql;
alter table HypRelDeathInd.ChiSqResults
modify prob format=pvalue5.2, value format=7.2;
quit;