Add header field to SAS dataset

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Add header field to SAS dataset

Hello and good morning,

I am beginner at SAS programming and so if my question seems trivial please excuse me.

I have a fixed length file which I am importing into SAS. The file looks something like this

HDR*******TYPE1*********************

record1

record2

record3

.....

.....

HDR*******TYPE2*********************

record11

record12

record13

.....

.....

I need to attach the header record "TYPE1" to records 1,2,3 and "TYPE2" to records 11,12,13. Can you please help me understand how this can be done. I have around 30 files like this which I need to import.

Thank you very much.im


Accepted Solutions
Solution
‎02-05-2013 10:18 AM
Super User
Super User
Posts: 6,347

Re: Add header field to SAS dataset

Use a RETAIN statement.

Something like this.

data want ;

  infile 'myfile' ;

  retain HDR ;

  input @;

  if _infile_ =: 'HDR' then do;

      HDR=_infile_;

      delete;

  end;

  else input record;

run;

View solution in original post


All Replies
Solution
‎02-05-2013 10:18 AM
Super User
Super User
Posts: 6,347

Re: Add header field to SAS dataset

Use a RETAIN statement.

Something like this.

data want ;

  infile 'myfile' ;

  retain HDR ;

  input @;

  if _infile_ =: 'HDR' then do;

      HDR=_infile_;

      delete;

  end;

  else input record;

run;

New Contributor
Posts: 2

Re: Add header field to SAS dataset

Tom,

Unfortunately, I was not even familiar with RETAIN , _infile_, input @. However I tried reading up on it and understand what you had written. I am 80% sure I understand what is happening. And, it seems like the code is working. I will be QAing the files tomorrow.

However, I wanted to say thank you so much. I didnt know where to go and this has helped me more than you know.

You Sir are a genius.

Have a wonderful day.

Abhijit

Frequent Learner
Posts: 1

Re: Add header field to SAS dataset

such a bad language i ever seen, too complicated to do any thing.
i like its statistical power, but not the way its coded... haate it honestly because it eats away my time to learn the syntax being different from all...
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 773 views
  • 1 like
  • 3 in conversation