09-18-2013 02:57 PM
Hi, I have a bunch of tab-delimited text files that have the following format:
When I proc import, the labels are brought in as the first line of data. I was wondering if there was anyway for SAS to make these labels instead, or better yet, to test that the second line is/isn't labels each time it imports.
09-18-2013 03:20 PM
If they are all in the same format then I would take the code generated, it should show in the log, and modify it to use the option firstobs=3 on the INFILE statement and then use the labels in the data to add labels to the data.
It might simplify the project to make one copy of the data with the label line deleted so that data types are chosen more appropriately by the import generated code.
To simplify making the label code you can try opening the file in a spread sheet and copy the first two lines the post in another sheet to transpose to columns. If familiar with concatenation in the spread sheet you can then make one column with
var = "label"
to copy and paste into a label statement.
Because I want to control length of character variables, informats, formats and labels I seldom use the default generated by proc import. If the files are supposed to contain similar data it is a good idea to look at the lengths of character variables and ensure they are long enough for values in all of the files.
09-18-2013 03:41 PM
Thanks ballardw. Yea, I was trying to avoid using the obs option, since I still need to keep the variable names. And I was hoping to do all this without having to manually change the text file since there are quite a few of them. My only thought right now is to delete the second observation with each import, but there's still the problem with all the number variables being in character format because of it.
09-18-2013 03:52 PM
Are all of the files in the same layout or each different?
Also, if you run proc import on file without the label row if you use the DATAROW=2 option then the numeric data should come in fine with the first row providing variable names.
09-18-2013 04:27 PM
@ ballardw: Ah, datarow=2 (or would it be 3?) seems like it will work. The labels aren't too important. But it would be nice to be able to assign them via something like labelrow=x.
@ data_null_;: There isn't any data documentation, but the data are nothing too crazy, and best32 should work just fine. But if you have any idea how I can assign a certain row in the file as labels, I would love to know.
09-18-2013 04:06 PM
I would just write my own code to read the names and make labels from row 2. Do you really want PROC IMPORT to guess at the data type? Do you have documentation that tells you what the datatype of each variables is?
09-19-2013 08:53 AM
With DATAROW=3 to skip the label row we can turn our attention to labels. This is a bit fiddley with code generation but you could package the IMPORT and labels bit with a macro.