Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8270325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:32:37+00:00 2026-06-08T06:32:37+00:00

So I have a rather messy text file I’m trying to convert to a

  • 0

So I have a rather messy text file I’m trying to convert to a sas data set. It looks something like this (though much bigger):

0305679  SMITH, JOHN  ARCH05  001  2
ARCH05  005  3
ARCH05  001  7

I’m trying to set 5 separate variables (ID, name, job, time, hours) but clearly only 3 of the variables appear after the first line. I tried this:

infile "C:\Users\Desktop\jobs.txt" dlm = '  ' dsd missover;
input ID $ name $ job $ time hours;

and didn’t get the right output, then I tried to parse it

infile “C:\Users\Desktop\jobs.txt” dlm = ‘ ‘ dsd missover; input
allData $; id = substr(allData, find(allData,”305″)-2, 7);

but I’m still not getting the right output. Any ideas?

EDIT: I’m trying now to use .scan() and .substr() to apart the larger data set, how do I subset a single line from the data?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T06:32:38+00:00Added an answer on June 8, 2026 at 6:32 am

    Your data might not be all that messy; it just might be in a hierarchical format where the first row contains all five variables and subsequent rows contain values for variables 3-5. In other words, ID and NAME should be retained as you read through the file.

    If that is correct (it’s a hierarchical layout) this here is a possible solution:

    data have;
       retain ID NAME;
       informat ID 7. JOB $6. TIME 3. HOURS 1.;
       input @1 test_string $7. @;
       if notdigit(test_string) = 0
          then input @1 ID NAME $12. JOB time hours;
          else input @1 JOB time hours;
       drop test_string;
       datalines;
    0305679  SMITH, JOHN  ARCH05  001  2 
    ARCH05  005  3 
    ARCH05  001  7 
    0305680  JONES, MARY  ARCH06  002  4 
    ARCH06  005  3 
    ARCH07  001  7 
    run;
    

    The key thing is to really understand how your raw file is organized. Once you know the rules, using SAS to read it is a snap!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rather large text corpus, of which I would like to check
I have a rather enormous project in which I'm trying to retrofit in-memory data.
I have a rather large text file that has a bunch of missing newlines,
I currently have a hierarchy that looks like this MainWindowViewModel TabViewModel EditorViewModel ReviewingServices ConflictFinder
I'm trying to do something a bit different with subheaders whereby the text looks
Let's say I have some code like this if(isset($_GET['foo'])) //do something if(isset($_GET['bar'])) //do something
I have a rather large SQL file which starts with the byte order marker
I've inherited a rather large and somewhat messy codebase, and have been tasked with
I'd like to have an image next to the text on each row of
I have a variable that is... $whatever = 5865/100; This is a text variable.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.