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: 7914
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: 7914
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: 7914
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: 7914
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: 961
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: 7914
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
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm
No new posts How to update a portion of text in a ... Bill Woodger DFSORT/ICETOOL 25 Wed Nov 09, 2016 9:41 pm
No new posts Two Selects in a single select query Rohit Umarjikar DB2 1 Fri Nov 04, 2016 8:46 pm
This topic is locked: you cannot edit posts or make replies. Rexx to create GDG by scanning JJ result krish.deepu CLIST & REXX 5 Tue Oct 25, 2016 5:32 pm
No new posts Problem in Running Query via JCL vickey_dw DB2 3 Tue Oct 18, 2016 11:11 pm


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