View previous topic :: View next topic
|
Author |
Message |
s2nd2
New User
Joined: 08 Aug 2008 Posts: 6 Location: hyd
|
|
|
|
hi,
I need to count total number of records from an input file in to one o/p file using SAS. The O/P file should display the number of records in the fromat of 99,99,999. Iam using COUNT+1 to count the records. Please let me know how can i get a report with data 99,99,999. when i was using fomat count COMMA. -
FORMAT COUNT COMMA.
FILE SASREPT;
PUT @4 'TOTAL RECORDS: ' COUNT;
it is showing a value of 1.61E6(which is not in the from of 99,99,999) in the SASlog instead of in the O/p file.
thanks, |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
FORMAT COUNT COMMA.
will default to the length of 8, so not surprising you get exponential output.
Set the output length to something more reasonable for a large record count. |
|
Back to top |
|
|
s2nd2
New User
Joined: 08 Aug 2008 Posts: 6 Location: hyd
|
|
|
|
in future the number of records may be large ....at this time i cant format it to comma20 rite...its based on the number of records....
i hv also mentioned that the count is not written in to the SAS file........
please provide is there is any better approach..........for these
i dont know much about SAS,,,,but iam trying to get something for this.... |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
Quote: |
at this time i cant format it to comma20 |
I usually use either COMMA19. or COMMA32. |
|
Back to top |
|
|
s2nd2
New User
Joined: 08 Aug 2008 Posts: 6 Location: hyd
|
|
|
|
THANK YOU VERY MUCH.............
BUT WHERE CAN I USE THIS FORMAT....
WHEN I UESD BEFORE WRITING INTO THE O/P FILE......THE TOTAL REPORT WAS GENERATED IN SAS LOG..AND THE O/P FILE WAS EMPTY. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
Take a look at the code that I have used. This only reads a record and increments the counter until EOF.
The FILE statement points to the DDNAME where the output will be written to.
Code: |
DATA _NULL_;
FORMAT COUNT COMMA32.;
INFILE DATEFILE EOF=EOF1;
INPUT @01 DATEIN PD4.;
COUNT + 1;
RETURN;
EOF1:
FILE TESTOUT;
PUT @01 'COUNT WAS ' COUNT;
|
|
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
The file that you want to count the records from ......... is it a flat file or a SAS file ? |
|
Back to top |
|
|
s2nd2
New User
Joined: 08 Aug 2008 Posts: 6 Location: hyd
|
|
|
|
Its a VSAM file.....
Iam able to get the o/p file now.......thanks for all ur help....
Thanks, |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
Please post your code for the benfit of others, because I know that VSAM files can be a bit of a pain in SAS.
But ................... IDCAMS LISTCAT would give you the record count, and does not have to read through the file.
When the file gets closed the record count is updated in the catalog, and LISTCAT will get the number of records in the file. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Quote: |
I know that VSAM files can be a bit of a pain in SAS |
Not only is VSAM a 4-letter word, but now it is a pain in the SAS. . .
Happy Weekend
d |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
Not only is VSAM a 4-letter word, but now it is a pain in the SAS |
groan ... Dick, how could you?
I've never had any problems with VSAM files in SAS; reading them sequentially requires only one difference from a sequential file (the VSAM keyword on the INFILE statement). Reading them randomly isn't as easy in SAS as COBOL but it doesn't require a rocket scientist either. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Quote: |
groan ... Dick, how could you? |
Devil made me. . . Thought i'd see who i could punish. . .
Oh, yeah, today is 888, not 666. . . |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
Oh, yeah, today is 888, not 666. . . |
meaning what? You're one-third MORE evil? |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
Dick, surely tou meant COMMA888. |
|
Back to top |
|
|
s2nd2
New User
Joined: 08 Aug 2008 Posts: 6 Location: hyd
|
|
|
|
Quote: |
Please post your code for the benfit of others, because I know that VSAM files can be a bit of a pain in SAS. |
hi,
Iam using a VSAM file, but while reading iam not using any key.......but iam able to get the o/p with the count equal to i/p records in the input file.....
Let me know if iam doing aything wrong......
DATA MASTER_1
INFILE MASTER EOF=TOTALS;
INPUT @42 DATAT PD4.;
COUNT+1;
here my inout file is MASTER;
Thank You, |
|
Back to top |
|
|
|