DATA Step, Macro, Functions and more

How to read in a dataset with multiple lines per record properly

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

How to read in a dataset with multiple lines per record properly

I have a dataset which is in the format that there are multiple lines per observation and the delimiter is a space between the columns. I have written a code to read in the dataset but I am having trouble reading it in properly. The issues I am facing are: 1. The DOB variable doesnot show the correct year of the people 2. I had to read in the SalaryStart and SalaryEnd as Character while I want to read it in as numeric. 3. The gender field has not been read in correctly. However, doing so yields only missing values. 3.Some of the values are getting mixed in different columns. I will really appreciate any help to straighten out my code. I have attached the dataset and the code to this message.

Thanks in advance,

Biobee

Message was edited by: Biobee bh

Attachment
Attachment

Accepted Solutions
Solution
‎09-27-2012 09:27 PM
Occasional Contributor
Posts: 6

Re: How to read in a dataset with multiple lines per record properly

Your code works like a charm.

View solution in original post


All Replies
Valued Guide
Posts: 765

Re: How to read in a dataset with multiple lines per record properly

hi ... try this ...

data employment;

infile 'z:\employment.txt' truncover;

input

@01 name           $17.

@20 startdate      mmddyy10.

@36 salarystart    comma7.

@43 enddate        mmddyy10.

@58 salaryend      comma7.    

/

@01 maritalstatus  $8.

@16 gender         $1.

/

@07 dob            mmddyy10.

;

format startdate enddate mmddyy10. dob worddate20. salary: dollar8.;

run;

proc print data=employment;

run;

Super Contributor
Posts: 1,636

Re: How to read in a dataset with multiple lines per record properly

Hi MIke,

What is the '/' for between the two lines?

@16 gender         $1.

/

@07 dob            mmddyy10.


Thanks!

Occasional Contributor
Posts: 6

Re: How to read in a dataset with multiple lines per record properly

Hi Linlin,

the / is for SAS to recognise that the record has continued on the next line.

cheers

Biobee

Valued Guide
Posts: 765

Re: How to read in a dataset with multiple lines per record properly

hi Linlin ... it means move to a new record in the file being read

Super Contributor
Posts: 1,636

Re: How to read in a dataset with multiple lines per record properly

Thank you Mike!!!

Solution
‎09-27-2012 09:27 PM
Occasional Contributor
Posts: 6

Re: How to read in a dataset with multiple lines per record properly

Your code works like a charm.

Valued Guide
Posts: 765

Re: How to read in a dataset with multiple lines per record properly

hi ... so is it merely "helpful" or is it "correct" ... inquiring minds would like to know

☑ This topic is solved.

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

Discussion stats
  • 7 replies
  • 281 views
  • 4 likes
  • 3 in conversation