![]() ![]() If you will use the macro variable and the %do-loop, be sure to include all of your code in a macro, otherwise the loop will give an error. This is definitely an issue, however I have found that it is much easier type converting the variables on demand, rather than typing each variable one by one in the input statement. Of course this leaves the problem that all values are imported as characters. This will create the dataset that you want without worrying if the file structure has changed (columns were added or removed) which makes your code more dynamic. Now you can loop through the macro variable instead of writing each column name and type one by one: data inputFile (compress=binary) The error you get might actually be related to this) In general, using a space as a delimiter might not be a good idea - this applies if you have string fields containing spaces themselves. The above codes creates a macro-variable called headers with the column names separated by spaces (the tranwrd() function basically replaces the ',' with ' ' because I usually work with csv files so this might not be necessary for you. Select distinct tranwrd(compress(line),","," ") as lineTest length=32767 into: headers from headers length The above step creates a dataset that has one observation that contains all the column headers separated by your delimiter. One possible solution to this is: data headers ĭlm = "_" /*make sure to here to use a delimiter DIFFERENT from the real one to keep everything in one observation*/ Of course, the code above is not very practical in cases of long txt files with a great number of columns as you would have to type each column label with its data type on your own. (Should this be treated as an empty column and leave one value blank as it reads the next one or just pull the next available value in?) You can find more info on what these options do here.įor example the missover option tells sas what to do in case it finds two consecutive delimiters. The problem with proc import is that it tries to 'guess' the correct options (such as dsd, missover, etc.) and datatypes and it does not always succeed. The code above is more or less what the proc import does. If you are the one that created the file the you might check if the system you are using has a way to not put the NA into the file to begin with. *do this for every variable (column) in you. 1 Did you create that text file from R That package has a nasty habit of putting text values of NA for numeric values into text files. *numbers of all types ints, floats, etc */ You can instead use the infile command inside of a datastep: data input_data Generally after lots of unsuccessful tries of proc import i decided that it is better to be avoided as it sometimes comes up with surprising results. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |