BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
soujik
Calcite | Level 5

Hi, 

Quick question on count and format

 

select xx_yy,

       count(1) format = comma12. as aci_knt

From wkly_wxxx_fnl

 

what does the count and format do in this code. please help me

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@soujik wrote:

what does the comma12.

 

is it put comma after 12 digits? 


As I said, it adds commas properly to your number. I have never seen a number with a comma after 12 digits. Since two people have given you a link to the documentation for the COMMA format, you can also look at the examples there.

--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Count(1) counts the number of records in column 1 (which is the variable named xx_yy), which is also the same as the number of records in the data set; and format displays the result using the COMMA. format (in other words, with appropriate commas).

--
Paige Miller
soujik
Calcite | Level 5

what does the comma12.

 

is it put comma after 12 digits? 

PaigeMiller
Diamond | Level 26

@soujik wrote:

what does the comma12.

 

is it put comma after 12 digits? 


As I said, it adds commas properly to your number. I have never seen a number with a comma after 12 digits. Since two people have given you a link to the documentation for the COMMA format, you can also look at the examples there.

--
Paige Miller
Tom
Super User Tom
Super User

COUNT() counts the number of times is argument is not missing.  So COUNT(1) is the same thing as COUNT(*), it just counts the number of observations.

 

FORMAT= is used to attach a format to the variable.  The COMMA format is used to display number with a comma as the thousands separator.  12 is the width of the format, how many bytes it prints.  So COMMA12 will show numbers in the style of ,234,678,012 .  So use 12 is a little silly for positive numbers.  Either use COMMA11. if you expect numbers smaller than 1 billion or use something wider than 12 if you expect counts over 1 billion.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 871 views
  • 1 like
  • 4 in conversation