Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Need to create header record from SAS query.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> All Other Mainframe Topics
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    Post subject: Need to create header record from SAS query.
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: 7996
Location: Bellevue, IA

PostPosted: Thu Feb 17, 2011 8:23 pm    Post subject:
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    Post subject:
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: 7996
Location: Bellevue, IA

PostPosted: Thu Feb 17, 2011 10:15 pm    Post subject:
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    Post subject:
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: 7996
Location: Bellevue, IA

PostPosted: Thu Feb 17, 2011 10:41 pm    Post subject:
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    Post subject:
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: 7996
Location: Bellevue, IA

PostPosted: Thu Feb 17, 2011 10:57 pm    Post subject:
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    Post subject:
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

Active Member


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

PostPosted: Fri Feb 18, 2011 9:33 am    Post subject:
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: 7996
Location: Bellevue, IA

PostPosted: Fri Feb 18, 2011 9:53 am    Post subject:
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    IBMMAINFRAMES.com Support Forums -> All Other Mainframe Topics All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Record Not found in AlX but record re... mukun264 COBOL Programming 5 Fri Mar 24, 2017 9:28 am
No new posts Count the length of the record & ... sreekusr DFSORT/ICETOOL 4 Thu Mar 23, 2017 7:52 pm
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts IMS DB-How to update a record (a sing... Nic Clouston IMS DB/DC 9 Thu Mar 09, 2017 4:38 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us