Help using Base SAS procedures

Reading Mixed Raw Data

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 16
Accepted Solution

Reading Mixed Raw Data

**Fictional Content used**

Hello,

I'm trying to read in a staggered raw data file with various column widths but you see that I cannot successfully use a pointer

(i.e. @19 or +2) since the Employee_Name variable isn't a fixed column.  How do I best achieve results such that they appear as expected?

RAW DATA

(Level1) Chief Executive Officer  (Anthony Miller )                              $433,800

         (Level2) Chief Sales Officer  (Harry Highpoint )                         $243,190

         (Level2) Chief Financial Officer  (Max Crown )                           $268,455

EXPECTED

Level             Job_Title                              Employee_Name               Salary

1                    Chief Executive Officer       Anthony Miller                    $433,800

2                    Chief Sales Officer             Harry Highpoint                  $243,190

2                    Chief Financial Officer        Max Crown                         $268,455

My code is as follows:

Work.Unicorn;

infile "rawin.dat" missover truncover;

length Level $ 8.;

input Level @;

if Level="(Level1)" then

     input @10 Job_Title $25. @35 Employee_Name $18. @108 Salary dollar8.;

else if Level="(Level2)" then

     input Job_Title $ +2;

run;

Thank you for any assistance,

David


Accepted Solutions
Solution
‎12-05-2014 06:51 PM
Respected Advisor
Posts: 4,173

Re: Reading Mixed Raw Data

Then please mark the answer which is closest to what you wanted as "correct" so that this question gets "ticked off" as answered.

View solution in original post


All Replies
Respected Advisor
Posts: 4,173

Re: Reading Mixed Raw Data

You will need to get the informats right - but else below code should give you the idea.

data want;

  infile datalines truncover dlm='()' dsd;

  input dummy :$1 (Level Job_Title Employee_Name Salary) (:$20.);

  datalines;

(Level1) Chief Executive Officer  (Anthony Miller )                              $433,800

         (Level2) Chief Sales Officer  (Harry Highpoint )                         $243,190

         (Level2) Chief Financial Officer  (Max Crown )                           $268,455

run;

Super User
Posts: 19,876

Re: Reading Mixed Raw Data

I would read the first portion as a single text field and then parse it using the scan function with the () as delimiters.

Occasional Contributor
Posts: 16

Re: Reading Mixed Raw Data

Thank you all.

I overlooked using () as delimeters.  Thanks for the info.

David

Solution
‎12-05-2014 06:51 PM
Respected Advisor
Posts: 4,173

Re: Reading Mixed Raw Data

Then please mark the answer which is closest to what you wanted as "correct" so that this question gets "ticked off" as answered.

🔒 This topic is solved and locked.

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

Discussion stats
  • 4 replies
  • 206 views
  • 6 likes
  • 3 in conversation