DATA Step, Macro, Functions and more

adding record for multiple rows

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

adding record for multiple rows

​i have fixed length file which has 5 segments and each segment in turn has 20 columns each for 1000 records.

i want to group  all segments together and do maupulation and then assign them back to the records they belong.

but there is no primary key for combining the segments back to their respective record and hence wnt to make a common id for all the segments belonging to each individual record

 

i.e want to create something like this so that i can take each segment convert the fixed length to columns and then assign each segment to their respective record based on the record id.

 

record       
1address segment     
v1v2v3v4v5v6
borrower segmrnt     
b1b2b3b4
demog segment     
2address segment     
v1v2v3v4v5v6
borrower segmrnt     
b1b2b3b4
demog segment     

Accepted Solutions
Solution
‎01-13-2018 10:52 AM
Super User
Posts: 13,886

Re: adding record for multiple rows

Assuming in your actual data file each record format HD, BS, AS etc. occur on a single line then something like this skeleton program may help.

 

data want;
   infile "your file" dlm='|' lrecl=32000;
   informat block $2.;
   /*informats to describe other variables to be read go here*/
   input block @;
   /* each input statement below should read the variables
      for that block
   */
   Select (block);
      when ('AS')
         input ASvar1 ASvar2 ASvar3 ;
      when ('BS')
         input bsvar1 bsvar2 bsvar3 ;
      when ('CS')
         input CSvar1 CSvar2 CSvar3 ;
      when ('HD')
         input HDvar1 HDvar2 HDvar3 ;
      when ('RS')
         input RSvar1 RSvar2 RSvar3 ;
     otherwise;
   end;
run;

You would have to supply the variable names and attributes from some documentation.

 

View solution in original post


All Replies
Super User
Posts: 10,530

Re: adding record for multiple rows

[ Edited ]
New Contributor
Posts: 3

Re: adding record for multiple rows

Posted in reply to KurtBremser

kindly find attached the sample data.

here HD BS AS RS and CS represents the 5 segments and data corresponding to them are the different fields in fixed length.

this is an example of only 1 record

Super User
Posts: 10,530

Re: adding record for multiple rows

So it looks that you have groups of records with different record types, recognizable by the value in the first 2-character column.

Each block starts with a 'BS' and ends with a 'CD'.

Can you supply the structure for the BS, AS, RS, CR, GS, SS and CD lines? And how you expect that to end up in a SAS dataset or in a group of datasets?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Solution
‎01-13-2018 10:52 AM
Super User
Posts: 13,886

Re: adding record for multiple rows

Assuming in your actual data file each record format HD, BS, AS etc. occur on a single line then something like this skeleton program may help.

 

data want;
   infile "your file" dlm='|' lrecl=32000;
   informat block $2.;
   /*informats to describe other variables to be read go here*/
   input block @;
   /* each input statement below should read the variables
      for that block
   */
   Select (block);
      when ('AS')
         input ASvar1 ASvar2 ASvar3 ;
      when ('BS')
         input bsvar1 bsvar2 bsvar3 ;
      when ('CS')
         input CSvar1 CSvar2 CSvar3 ;
      when ('HD')
         input HDvar1 HDvar2 HDvar3 ;
      when ('RS')
         input RSvar1 RSvar2 RSvar3 ;
     otherwise;
   end;
run;

You would have to supply the variable names and attributes from some documentation.

 

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 133 views
  • 1 like
  • 3 in conversation