10-26-2012 06:01 PM
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:
put _infile_ hex.;
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.
10-26-2012 06:32 PM
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
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!
/* 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'
Richard in Oz
10-26-2012 06:49 PM
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.
10-26-2012 08:04 PM
How are you doing with your problem so far? Like to post some code for review?
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
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
10-26-2012 08:24 PM
You didn't include what was already suggested. Try:
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;
10-26-2012 11:02 PM
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
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;
retain feature timestamp value;
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
10-27-2012 09:32 AM
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.