- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi I have below data and I need to provide header for this.
Input Data set: 100 018 XX
200 172 ZZ
Desired Output: A B C
100 018 XX
200 172 ZZ
I only want this output in a data set, not in a report.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Assuming that you want to put it into a text file and are just calling it a data set because of confusion with old mainframe terminology for a disk file.
The problem with adding a "HEADER" to a fixed format file is just how to make those meaningful. What if you are writing a single byte code for GENDER then where in the first line can you write the heading for that column?
But assuming you have figured that out then just use the automatic variable _N_ to tell when you are on the first observation and write the header line then.
data _null_;
set have ;
file 'output_file' ;
if _n_=1 then the put ' A B C';
put (A B C) (3.);
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can't put character data into numeric variables, so this won't be possible.
What for do you want to do that, anyway? Columns have names, and additional information can be put into column labels.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Kurt_Bremser I am creating a flat file on mainframes, and i want to put labels or header (since this will be only on the first record) on the data on fixed positions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You were specifically talking about a dataset, quote:
I only want this output in a data set, not in a report.
Please make up your mind.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If you want to put in a header in a typical fixed-length mainframe file, do this:
data have;
input a b c $;
cards;
100 018 XX
200 172 ZZ
;
run;
data _null_;
set have;
file '$HOME/sascommunity/flatfile' recfm=f lrecl=8;
if _n_ = 1 then put ' A B C';
put
a z3.
b z3.
c $2.
;
run;
You will have to use MF-style file syntax, of course, probably a fileref derived from a DD in the JCL that calls the SAS program. Just make sure that your SAS lrecl matches the LRECL in the JCL, and fits your lengths of the put statements
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
There is a logical conflict between title and description: the title reads "How to put header in a fixed format file?" and later on you write "I only want this output in a data set, not in a report.". Why do you want that text in a dataset? Does not make sense, especially because all variables have to be converted to alphanumeric before a title-observation could be added.
Posting the code you are using to create the fixed format text file will make it easier to suggest something useful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Why can't we add header record here? Can we add labels on fixed positions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please read my post again, i explained what is necessary to add a header observation. And i repeat: this is not recommended! Writing additional lines of text while creating the text file, is possible. You don't have to add that row to the dataset.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Assuming that you want to put it into a text file and are just calling it a data set because of confusion with old mainframe terminology for a disk file.
The problem with adding a "HEADER" to a fixed format file is just how to make those meaningful. What if you are writing a single byte code for GENDER then where in the first line can you write the heading for that column?
But assuming you have figured that out then just use the automatic variable _N_ to tell when you are on the first observation and write the header line then.
data _null_;
set have ;
file 'output_file' ;
if _n_=1 then the put ' A B C';
put (A B C) (3.);
run;