Learning SAS? Welcome to the exclusive online community for all SAS learners.

FORMAT COMMA. statement does not affect 2 first rows in report

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

FORMAT COMMA. statement does not affect 2 first rows in report

I am doing "Practice" section of SAS Programming 1 course, lesson 9.

 

My code is as below:

data work.increase;
   set orion.staff;
   Increase = Salary*0.10;
   NewSalary = SUM(Salary, Increase);
   BdayQtr = QTR(Birth_Date);
   KEEP  Employee_ID Salary Birth_Date Increase NewSalary BdayQtr;
   FORMAT Salary Increase NewSalary COMMA.;
run;

PROC PRINT DATA=work.increase LABEL;
RUN;

 

After click "Run", the output report in Result tab is as below:

 

Obs Employee ID Employee Annual Salary Employee Birth Date Increase NewSalary BdayQtr 1 2 3 4 5 6

12010116304018AUG198016,3041793443
12010210825511AUG197310,8261190813
12010387,97522JAN19538,79896,7731
12010446,23011MAY19584,62350,8532
12010527,11021DEC19782,71129,8214
12010626,96023DEC19482,69629,6564

 

As you can see, the FORMAT COMMA. statement does not affect the display of 2 first rows of NewSalary variable.

 

I am confusing what happens.


Accepted Solutions
Solution
a week ago
Super User
Posts: 7,444

Re: FORMAT COMMA. statement does not affect 2 first rows in report

The default width for the comma. format is 6.

Since you did not specify a width, SAS now tries to fit values into those 6 digits as best as it can. Your 6-digit values are therefore displayed using the best. format.

Use a width:

format Salary Increase NewSalary comma10.;

which should give you some reserve space for larger numbers.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
a week ago
Super User
Posts: 7,444

Re: FORMAT COMMA. statement does not affect 2 first rows in report

The default width for the comma. format is 6.

Since you did not specify a width, SAS now tries to fit values into those 6 digits as best as it can. Your 6-digit values are therefore displayed using the best. format.

Use a width:

format Salary Increase NewSalary comma10.;

which should give you some reserve space for larger numbers.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Highlighted
New Contributor
Posts: 4

Re: FORMAT COMMA. statement does not affect 2 first rows in report

I see, thank you very much!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 142 views
  • 1 like
  • 2 in conversation