BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASInd
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

 

View solution in original post

8 REPLIES 8
Kurt_Bremser
Super User

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.

SASInd
Obsidian | Level 7

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.

Kurt_Bremser
Super User

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

andreas_lds
Jade | Level 19

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.

 
SASInd
Obsidian | Level 7

Why can't we add header record here?  Can we add labels on fixed positions?

 

 

andreas_lds
Jade | Level 19

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.

Tom
Super User Tom
Super User

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;

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 7054 views
  • 1 like
  • 4 in conversation