From: "Keintz, H. Mark" on 19 Jun 2007 14:03 A.K. Lee wrote: > I have a bunch of dollar delimited files for conversion to SAS datasets. > I've written a small macro code using Proc import with guessing rows=1000 > (needed as some colums have a lot of numerical data with few character > values). It works fine, only issue is that occasionaly a couple of files > are empty (i.e they have column headers but no data values). > > In such a case, I still want empty SAS datasets to be created giving the > variable names. However if there are no datavalues, SAS gives an error such > as this: "Unable to sample external file, no data in first 5 records." > > Thanks very much in advance, > -A If you have no data records, then how to expect to determine variable type? And if you were somehow to know that some vars are character vars, how would you assign their lengths? Mark Keintz Wharton Research Data Services
From: David L Cassell on 20 Jun 2007 01:11 aktivelee(a)YAHOO.COM wrote: > >Hi- > >I have a bunch of dollar delimited files for conversion to SAS datasets. >I've written a small macro code using Proc import with guessing rows=1000 >(needed as some colums have a lot of numerical data with few character >values). It works fine, only issue is that occasionaly a couple of files >are empty (i.e they have column headers but no data values). > >In such a case, I still want empty SAS datasets to be created giving the >variable names. However if there are no datavalues, SAS gives an error such >as this: "Unable to sample external file, no data in first 5 records." > >Thanks very much in advance, >-A If you have dollar-delimited files, then they are text files. So you could read them in using a data step instead. If you want an empty SAS data set from a file with nothing but a column header, then I'll guess that al lthese files have the same variables, or at least the same variables always have the same types/informats/formats and so on. So are these all the same files but for different days or sites or something? If so, then I would recommend that you store them in a single SAS data set. And I would recommend that you try reading all the files in together, instead of separately with a macro. SAS will let you read in a whole clod of files with a wildcard, like this: infile 'C:\your\path\*.txt' dlm='$'; So perhaps you could read all the files, in one pass instead of dozens of passes. HTH, David -- David L. Cassell mathematical statistician Design Pathways 3115 NW Norwood Pl. Corvallis OR 97330 _________________________________________________________________ PC Magazine�s 2007 editors� choice for best Web mail�award-winning Windows Live Hotmail. http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_pcmag_0507
From: "Howard Schreier <hs AT dc-sug DOT org>" on 21 Jun 2007 16:08 On Tue, 19 Jun 2007 14:03:36 -0400, Keintz, H. Mark <mkeintz(a)WHARTON.UPENN.EDU> wrote: >A.K. Lee wrote: > >> I have a bunch of dollar delimited files for conversion to SAS >datasets. >> I've written a small macro code using Proc import with guessing >rows=1000 >> (needed as some colums have a lot of numerical data with few >character >> values). It works fine, only issue is that occasionaly a couple of >files >> are empty (i.e they have column headers but no data values). >> >> In such a case, I still want empty SAS datasets to be created giving >the >> variable names. However if there are no datavalues, SAS gives an error >such >> as this: "Unable to sample external file, no data in first 5 records." >> >> Thanks very much in advance, >> -A > >If you have no data records, then how to expect to determine variable >type? Numeric by default; that's very consistent with the SAS data step. >And if you were somehow to know that some vars are character >vars, how would you assign their lengths? > >Mark Keintz >Wharton Research Data Services It's not as if PROC IMPORT does such a grat job when there are one or more lines of data values present. Essentially, it is trying to build a data set without the benefit of metadata, which is hard. However, I think AK's expectation is reasonable.
From: "Howard Schreier <hs AT dc-sug DOT org>" on 24 Jun 2007 12:16 On Mon, 18 Jun 2007 11:57:03 -0400, A.K. Lee <aktivelee(a)YAHOO.COM> wrote: >Hi- > >I have a bunch of dollar delimited files for conversion to SAS datasets. >I've written a small macro code using Proc import with guessing rows=1000 >(needed as some colums have a lot of numerical data with few character >values). It works fine, only issue is that occasionaly a couple of files >are empty (i.e they have column headers but no data values). > >In such a case, I still want empty SAS datasets to be created giving the >variable names. However if there are no datavalues, SAS gives an error such >as this: "Unable to sample external file, no data in first 5 records." > >Thanks very much in advance, >-A One workaround is to insert an all-missing record in the source file, then remove the resulting observation from the imported data set. See http://sascommunity.org/wiki/PROC_IMPORT_Will_not_Create_Zero-Row_Table
From: David Johnson on 24 Jun 2007 19:20 I've done this before Howard, under sufferance, to force the process to work correctly. However, if one is going to the effort of producing a macro then it seems to me that an extra step could be added before the import to get the data set structure into a model that persists when the import fails. Having said that, the Import Procedure strikes me as a quick and dirty way to get data in, and one can almost invariably do better and more consistently handle scruffy data with a well-crafted data step. I seem to recall that importing text files into data sets was day 1 of SAS 101. I might add too that creating a table structure for an empty table seems a little unusual. There is some factoid missing from this query that would make clear the reason for creating a table structure from an empty source. If the files were all of similar structure, then perhaps structural validation would be important, but when the files have differing structures, why would you want a structure when they haven't any data to offer to a subsequent process? Kind regards David -----Original Message----- From: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU]On Behalf Of Howard Schreier <hs AT dc-sug DOT org> Sent: Monday, 25 June 2007 2:17 AM To: SAS-L(a)LISTSERV.UGA.EDU Subject: Re: import variable names from delimited files On Mon, 18 Jun 2007 11:57:03 -0400, A.K. Lee <aktivelee(a)YAHOO.COM> wrote: >Hi- > >I have a bunch of dollar delimited files for conversion to SAS datasets. >I've written a small macro code using Proc import with guessing rows=1000 >(needed as some colums have a lot of numerical data with few character >values). It works fine, only issue is that occasionaly a couple of files >are empty (i.e they have column headers but no data values). > >In such a case, I still want empty SAS datasets to be created giving the >variable names. However if there are no datavalues, SAS gives an error such >as this: "Unable to sample external file, no data in first 5 records." > >Thanks very much in advance, >-A One workaround is to insert an all-missing record in the source file, then remove the resulting observation from the imported data set. See http://sascommunity.org/wiki/PROC_IMPORT_Will_not_Create_Zero-Row_Table
|
Pages: 1 Prev: error while importing file in sas Next: Panel Fixed Effects |