BookmarkSubscribeRSS Feed
efboggs
Fluorite | Level 6

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;

 

6 REPLIES 6
ballardw
Super User

@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.

efboggs
Fluorite | Level 6

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:

 

NOTE: ODS statements in the SAS Studio environment may disable some output features.
73
74
75 ODS OUTPUT ChiSq = ChiSqResults (KEEP= Statistic DF Value Prob
76 WHERE= (Statistic = 'Chi-Square'));
77 PROC FREQ
78 DATA = HTN;
79 TABLES HTNDeath * State / CHISQ NOPERCENT NOROW;
80 FORMAT Value 4.2;
WARNING: Variable VALUE not found in data set HTN.
81 FORMAT Prob 5.2;
WARNING: Variable PROB not found in data set HTN.
82 RUN;

 

ballardw
Super User

@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.
73
74
75 ODS OUTPUT ChiSq = HypRslt.ChiSqResults (KEEP= Statistic DF Value Prob
76 WHERE= (Statistic = 'Chi-Square'));
77 PROC FREQ
78 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.

abrice520
Obsidian | Level 7

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;

 

efboggs
Fluorite | Level 6

Ah thank you, that is super helpful!!

PGStats
Opal | Level 21

Add a small post-processing step:

 

proc sql;
alter table HypRelDeathInd.ChiSqResults 
modify prob format=pvalue5.2, value format=7.2;
quit;
PG

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
  • 6 replies
  • 1775 views
  • 1 like
  • 4 in conversation