BookmarkSubscribeRSS Feed
Sasman1441
Calcite | Level 5

help

8 REPLIES 8
art297
Opal | Level 21

Why does this sound like a homework assignment?

Rather than just giving you the solution, I'll make some suggestions.

First, what separates the fields?  You can find out by running some code like:

data test;

  infile 'C:\art\set13.txt';

  input;

  put _infile_;

  put _infile_ hex.;

  stop;

run;

Second, since you want your proc contents to reflect certain attributes like length and format, you should declare those up front and in the order you want the variables to appear when you run a proc contents.

Statements you will need: data, informat, format, length, infile (including delimiter and dsd options), input and run.

Now, my suggestion would be to try and, if it doesn't work correctly, post your code and ask whatever questions you might have.

RichardinOz
Quartz | Level 8

Arthur

Might be a little harsh on someone just starting out in SAS - getting the syntax for the infile is not blindingly obvious, especially the hex for the delimiter

SAShopeful

Here are some hints

Your file is a standard delimited file, but does not have headers.

If you inserted headers (the variable names separated by the same delimiter) you could use Proc Import

but the variables would be out of order so you would have to follow with a datastep or SQL to reorder them

This is the infile statement you need

Let me know if this is not a homework assignment!

data  Set13;

   /*    Specify file location and properties

        It is a standard delimited file => DSD

        but with tab delimiters so delimiter = '09'x (hex for tab)

        and without headers otherwise you would specify firstobs = 2

        You don't want it to flow onto the next data line if value is blank

        LRECL (logical record length) needs to be greater than the longest

        input text record, does not matter if it is very much longer

        */

   infile 'C:\Your File Folder\set13.txt'

           delimiter='09'x

           MISSOVER

           DSD

           LRECL=200

           ;

Richard in Oz

art297
Opal | Level 21

Richard: I wasn't trying to be harsh but, rather, help the poster learn SAS.  Methinks that dentifying a file's delimiter, by themselves, is an important part of that process.  Yes, many SAS statements are difficult to figure out, but many of us users know that and are quite willing to help irrespective of whether it is a work or homework task.

However, in both cases, I like to see that someone is trying, rather than just using the forum to have someone else do their work for them.

RichardinOz
Quartz | Level 8

SASman1441

How are you doing with your problem so far?  Like to post some code for review?

Arthur

While I agree with you in the value of reading the documentation and trying; that's how I learned most of SAS; I think that if this was a homework example for someone just starting out it was a bit much.  Wouldn't you set an example with some nicely behaved fixed length or space delimited data while the student wrestled with formats and remembering to terminate with semicolons?

I tend to think there are three kinds of knowledge about SAS

  1. Important features that you need to understand fully and know how to use without assistance
  2. Features that you don't need to remember, you just need to know where to look them up
  3. Syntax and other bits that you need occasionally but can just cut and paste into a solution

I started off pre version 5 on MVS, as it was then.  JCL was something I needed to get the job done, but it was enough to know how to copy, paste and modify while I wrestled with the real problems of wrestling with data analysis (Shock horror: I still do this when necessary).  I tend to view SAS Infile syntax in that light.  Confession:  I usually use the Windows SAS Import wizard for delimited data, then press F4 to retrieve the code and clean up the formats.

Sometimes wrestling with a problem can be self defeating.  Some time ago I spent many person hours trying to wrap single quotes around a resolved macro variable, exploring all the macro quoting functions, without success, and I gave up.  Eventually I saw a partial solution in someone else's code (ie %str(%')&example%str(%')) and I was able to adapt that to my requirements.  My point is that people can have blockages over stuff that does not have an intuitive solution, and getting them over that hurdle so they can do something useful is worthwhile.

Richard In Oz

art297
Opal | Level 21

You didn't include what was already suggested.  Try:

data set13;

  infile 'C:\Users\Julian\Desktop\data\Data\set13.txt' dlm='09'x dsd;

  informat feature $72.;

  format feature $80.;

  length feature $72;

  informat timestamp time8.;

  format timestamp time8.;

  format value 12.2;

  input timestamp feature value;

run;

Sasman1441
Calcite | Level 5

How did you develop your SAS skills?  Books or just experience programming?

RichardinOz
Quartz | Level 8

For some reason I'm not seeing the whole of this discussion here although belatedly I have come across your posts in my inbox.  Apologies for not responding at the time.

In response to your solution

data set13;

infile 'C:\Users\Desktop\data\Data\set13.txt' missover dsd dlm='09'x LRECL=200;

  informat timestamp time8. feature $72.;

  format value 12.2 timestamp time8. feature $80.;

  input timestamp feature value;

run;

data setF;

    retain feature timestamp value;

    set set13;

run;

It works, well done, but it could be improved.

The central thing to take away is that SAS builds a dataset (table) with columns in the order that it first sees them, which is why your retain statement managed the reordering (because otherwise the data variable order would have come from the SET statement and the set13 data.

You can avoid having to read the data twice by changing the order of the variables in your informat statement.  They do not have to be in the order you will use them in the input statement.  Effectively, that is what Arthur has done in his solution.

Arthur, you have been using SAS longer than I have (1981) but my recollection is in earlier versions of SAS the retain statement would not have worked because it would have made feature a numeric variable by default.  When did that change?

Richard in Oz

art297
Opal | Level 21

Richard,

I can't say one way or the other as I don't think I was even aware of the retain statement's existence until the late 90s.  Since then, at least, I think it has 'retained' its current behavior.  I've always wished that SAS would include a reorder statement, so that new users can accomplish variable reordering without first having the understand what the retain statement is really doing.

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
  • 8 replies
  • 1590 views
  • 0 likes
  • 3 in conversation