IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Need to create header record from SAS query.


IBM Mainframe Forums -> All Other Mainframe Topics
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ppandey07

New User


Joined: 27 Nov 2008
Posts: 51
Location: Delhi, India

PostPosted: Thu Feb 17, 2011 8:18 pm
Reply with quote

Hi,
I am using SAS for fetching data from Database.
I have fetched the data in das data. Now I want to format that data into flat file. In flat file I also need one header record.

So my questions are.
1)How can I create header record while copying data from SAS data set to flat file.

2) How can I count number of records copied and put in header record.

Thank you!!!
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Feb 17, 2011 8:23 pm
Reply with quote

Run a data step (HDRCOUNT) to count the records and output the count as a single record.

Run another data step to ouptut the data into a file and something like
Code:
DATA _NULL_;
     SET <data records>;
     FILE OUTFILE;
     IF _N_ = 1
     THEN DO;
          SET HDRCOUNT;
          PUT <header record with count>;
          END;
Back to top
View user's profile Send private message
ppandey07

New User


Joined: 27 Nov 2008
Posts: 51
Location: Delhi, India

PostPosted: Thu Feb 17, 2011 10:07 pm
Reply with quote

Robert Sample wrote:
Run a data step (HDRCOUNT) to count the records and output the count as a single record.

Run another data step to ouptut the data into a file and something like
Code:
DATA _NULL_;
     SET <data records>;
     FILE OUTFILE;
     IF _N_ = 1
     THEN DO;
          SET HDRCOUNT;
          PUT <header record with count>;
          END;


How can I run a data step (HDRCOUNT) to count the records and output the count as a single record?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Feb 17, 2011 10:15 pm
Reply with quote

Assuming DETAIL is the data set with the detail records:
Code:
DATA HDRCOUNT;
     SET DETAIL END=EOF;
     NRECS+1;
     IF EOF THEN OUTPUT;
or you can use a SET ioption to get the count directly but it's been a long time since I needed to do that so I don't remember the details. You could look it up on the SAS web site, of course.
Back to top
View user's profile Send private message
ppandey07

New User


Joined: 27 Nov 2008
Posts: 51
Location: Delhi, India

PostPosted: Thu Feb 17, 2011 10:36 pm
Reply with quote

ppandey07 wrote:
Robert Sample wrote:
Run a data step (HDRCOUNT) to count the records and output the count as a single record.

Run another data step to ouptut the data into a file and something like
Code:
DATA _NULL_;
     SET <data records>;
     FILE OUTFILE;
     IF _N_ = 1
     THEN DO;
          SET HDRCOUNT;
          PUT <header record with count>;
          END;


How can I run a data step (HDRCOUNT) to count the records and output the count as a single record?



Can you please let me know what should I put in <header record with count>.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Feb 17, 2011 10:41 pm
Reply with quote

How do you think I will know what your header record looks like? That should be something you ALREADY know!
Back to top
View user's profile Send private message
ppandey07

New User


Joined: 27 Nov 2008
Posts: 51
Location: Delhi, India

PostPosted: Thu Feb 17, 2011 10:54 pm
Reply with quote

Robert Sample wrote:
How do you think I will know what your header record looks like? That should be something you ALREADY know!


Yes you are correct. However, I wanted to ask that how would I use NRECS in my header record. Lets say my header record is like
"The total no. of records as per (today's date) is NRECS"

So how can I get that

Thank you!!!
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Feb 17, 2011 10:57 pm
Reply with quote

Code:
CD = TODAY();
FORMAT CD YYMMDDS10.;
PUT 'The total no. of records as per ' CD ' is ' NRECS;
Back to top
View user's profile Send private message
ppandey07

New User


Joined: 27 Nov 2008
Posts: 51
Location: Delhi, India

PostPosted: Thu Feb 17, 2011 11:03 pm
Reply with quote

Robert Sample wrote:
Code:
CD = TODAY();
FORMAT CD YYMMDDS10.;
PUT 'The total no. of records as per ' CD ' is ' NRECS;


Thank you very much!!! Have a nice day...
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Fri Feb 18, 2011 9:33 am
Reply with quote

How about proc sql?
Code:
select count(*) into :num from file;

creates a macro variable "num".

The next DATA step then uses %num.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Feb 18, 2011 9:53 am
Reply with quote

The SET statement option NOBS could also be used.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> All Other Mainframe Topics

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts FINDREP - Only first record from give... DFSORT/ICETOOL 3
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts RC query -Time column CA Products 3
Search our Forums:

Back to Top