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

**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

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

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

4 REPLIES 4
Patrick
Opal | Level 21

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;

Reeza
Super User

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

David_S
Fluorite | Level 6

Thank you all.

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

David

Patrick
Opal | Level 21

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

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 1049 views
  • 6 likes
  • 3 in conversation