Date: Fri, 30 Jun 2006 01:48:52 -0700
Reply-To: Joep <jsteeman@BUSINESSDECISION.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Joep <jsteeman@BUSINESSDECISION.COM>
Organization: http://groups.google.com
Subject: Re: trouble reading an instream file into a SAS dataset
Content-Type: text/plain; charset="iso-8859-1"
Rune,
I modifed your code. This works. I changed the following:
data Sakdok;
infile cards;
attrib
Saksnr length = $10
Arkiv_nokkelkode length = $16
Sakstittel length = $140
Saksdato length = 8 format = ddmmyy10.
Siste_dok length = 8 format = ddmmyy10.
Antall_dok length = 3 /* I made antall_dok numeric
*/
Saksansvarlig length = $12
Doknr length = 3 /* idem for doknr */
Javd length = $8
Sbh length = $12
Journaldato length = 8 format = ddmmyy10.
Uoff length = $6
Avsender_Mottaker length = $70
Dokumentbeskrivelse length = $140
AvskrDoknr length = 3 /* the same for avskrdoknr */
AvskrDato length = 8 format = ddmmyy10.
AvskrMaate length = $1
;
retain
Saksnr ''
Arkiv_nokkelkode ''
Sakstittel ''
Saksdato .
Siste_dok .
Antall_dok .
Saksansvarlig ''
Doknr .
Javd ''
Sbh ''
Journaldato .
Uoff ''
Avsender_Mottaker ''
Dokumentbeskrivelse ''
AvskrDoknr .
AvskrDato .
AvskrMaate ''
;
input;
if index(_infile_,'SAKSNR.:') then Saksnr =
substr(_infile_,index(_infile_,'SAKSNR.:')+9);
if index(_infile_,'ARKIV:') then Arkiv_nokkelkode =
substr(_infile_,index(_infile_,'ARKIV:')+7);
if index(_infile_,'TITTEL:') and index(_infile_,'DOK.TITTEL:')=0
then Sakstittel = substr(_infile_,index(_infile_,'TITTEL:')+9);
if index(_infile_,'SAKSDATO:') then Saksdato =
input(substr(_infile_,index(_infile_,'SAKSDATO:')+11), ddmmyy10.);
if index(_infile_,'SISTE DOK.:') then Siste_dok =
input(substr(_infile_,index(_infile_,'SISTE DOK.:')+12), ddmmyy10.);
if index(_infile_,'ANT.DOK:') then Antall_dok = INPUT
(substr(_infile_,index(_infile_,'ANT.DOK:')+9,3.), BEST.);
if index(_infile_,'SANSV.:') then Saksansvarlig =
substr(_infile_,index(_infile_,'SANSV.:')+8);
if index(_infile_,'DOKNR.:') and index(_infile_,'AVSKR.DOKNR.:') = 0
then Doknr = input(substr(_infile_,index(_infile_,'DOKNR.:')+8, 3.),
BEST.);
/* read doknr from position 8 instead of 9 */
if index(_infile_,'JAVD:') then Javd =
substr(_infile_,index(_infile_,'JAVD:')+6);
if index(_infile_,'SBH:') then Sbh =
substr(_infile_,index(_infile_,'SBH:')+5);
if index(_infile_,'JDATO:') then Journaldato =
input(substr(_infile_,index(_infile_,'JDATO:')+6), ddmmyy10.);
if index(_infile_,'UOFF') then Uoff =
substr(_infile_,index(_infile_,'UOFF')+6);
if index(_infile_,'AVS/MOT:') then Avsender_Mottaker =
substr(_infile_,index(_infile_,'AVS/MOT:')+9);
if index(_infile_,'DOK.TITTEL:') then Dokumentbeskrivelse =
substr(_infile_,index(_infile_,'DOK.TITTEL:')+12);
if index(_infile_,'AVSKR.DOKNR.:') then AvskrDoknr = INPUT
(substr(_infile_,index(_infile_,'AVSKR.DOKNR.:')+14,3.), BEST.);
/* because dato appears twice I inserted the second condition */
if index(_infile_,'DATO:') and not index(_infile_,'SAKSDATO:') then
AvskrDato = input(substr(_infile_,index(_infile_,'DATO:')+6),
ddmmyy10.);
if index(_infile_,'AVSKR. MÅTE:') then do;
AvskrMaate = substr(_infile_,index(_infile_,'AVSKR. MÅTE:')+13);
output;
end;
cards;
-----------------------------------------------------------------------------------------------
SAKSNR.: 1991/1
ARKIV: RAPPORTARKIV
TITTEL: GEOLOGICAL COMLETION REPORT PL 098 WELL 7120/10-2 NOVEMBER
1990
SAKSDATO: 02.01.1991 SISTE DOK.: 02.01.1991 ANT.DOK: 1
SANSV.: OD/ODH/KT
DOKNR.: 1 JAVD: ODJ SBH: OD/ODH/K
JDATO:02.01.1991 UOFF 5 A
AVS/MOT: ESSO
DOK.TITTEL: GEOLOGICAL COMLETION REPORT PL 098 WELL 7120/10-2
AVSKR.DOKNR.: DATO: 02.01.1991
AVSKR. MÅTE: X
-----------------------------------------------------------------------------------------------
SAKSNR.: 1991/2
ARKIV: RAPORTARKIV NR 9
TITTEL: RESERVOARTEKNISK RAPPORT STATFJORD NORD 1 EKS
SAKSDATO: 02.01.1991 SISTE DOK.: 02.01.1991 ANT.DOK: 1
SANSV.: OD/ODH/RO
DOKNR.: 1 JAVD: ODJ SBH: OD/ODH/R
JDATO:02.01.1991 UOFF FORTR
AVS/MOT: OD-S
DOK.TITTEL: RESERVOARTEKNISK RAPPORT STATFJORD NORD 1 EKS
AVSKR.DOKNR.: 3 DATO: 02.01.1991
AVSKR. MÅTE: X
-----------------------------------------------------------------------------------------------
run;
Rune Runnestø schreef:
> Hi,
> now I have made Antall_dok, Doknr and AvskrDoknr as character
> variables, and then perform an explicit data type conversion by means
> of the input function, but I still have the problem that Doknr is empty
> in the data set. How is that. Here is the recent code:
>
>
>
> data Sakdok;
> infile cards;
> attrib
> Saksnr length = $10
> Arkiv_nokkelkode length = $16
> Sakstittel length = $140
> Saksdato length = 8 format = ddmmyy10.
> Siste_dok length = 8 format = ddmmyy10.
> Antall_dok length = $3
> Saksansvarlig length = $12
> Doknr length = $3
> Javd length = $8
> Sbh length = $12
> Journaldato length = 8 format = ddmmyy10.
> Uoff length = $6
> Avsender_Mottaker length = $70
> Dokumentbeskrivelse length = $140
> AvskrDoknr length = $3
> AvskrDato length = 8 format = ddmmyy10.
> AvskrMaate length = $1
> ;
> retain
> Saksnr ''
> Arkiv_nokkelkode ''
> Sakstittel ''
> Saksdato .
> Siste_dok .
> Antall_dok ''
> Saksansvarlig ''
> Doknr ''
> Javd ''
> Sbh ''
> Journaldato .
> Uoff ''
> Avsender_Mottaker ''
> Dokumentbeskrivelse ''
> AvskrDoknr ''
> AvskrDato .
> AvskrMaate ''
> ;
> input;
>
> if index(_infile_,'SAKSNR.:') then Saksnr =
> substr(_infile_,index(_infile_,'SAKSNR.:')+9);
> if index(_infile_,'ARKIV:') then Arkiv_nokkelkode =
> substr(_infile_,index(_infile_,'ARKIV:')+7);
> if index(_infile_,'TITTEL:') and index(_infile_,'DOK.TITTEL:')=0
> then Sakstittel = substr(_infile_,index(_infile_,'TITTEL:')+9);
> if index(_infile_,'SAKSDATO:') then Saksdato =
> input(substr(_infile_,index(_infile_,'SAKSDATO:')+11), ddmmyy10.);
> if index(_infile_,'SISTE DOK.:') then Siste_dok =
> input(substr(_infile_,index(_infile_,'SISTE DOK.:')+12), ddmmyy10.);
> if index(_infile_,'ANT.DOK:') then Antall_dok = INPUT
> (substr(_infile_,index(_infile_,'ANT.DOK:')+9,3.), BEST.);
> if index(_infile_,'SANSV.:') then Saksansvarlig =
> substr(_infile_,index(_infile_,'SANSV.:')+8);
> if index(_infile_,'DOKNR.:') and index(_infile_,'AVSKR.DOKNR.:') = 0
> then Doknr = input(substr(_infile_,index(_infile_,'DOKNR.:')+9, 3.),
> BEST.);
> if index(_infile_,'JAVD:') then Javd =
> substr(_infile_,index(_infile_,'JAVD:')+6);
> if index(_infile_,'SBH:') then Sbh =
> substr(_infile_,index(_infile_,'SBH:')+5);
> if index(_infile_,'JDATO:') then Journaldato =
> input(substr(_infile_,index(_infile_,'JDATO:')+6), ddmmyy10.);
> if index(_infile_,'UOFF') then Uoff =
> substr(_infile_,index(_infile_,'UOFF')+6);
> if index(_infile_,'AVS/MOT:') then Avsender_Mottaker =
> substr(_infile_,index(_infile_,'AVS/MOT:')+9);
> if index(_infile_,'DOK.TITTEL:') then Dokumentbeskrivelse =
> substr(_infile_,index(_infile_,'DOK.TITTEL:')+12);
> if index(_infile_,'AVSKR.DOKNR.:') then AvskrDoknr = INPUT
> (substr(_infile_,index(_infile_,'AVSKR.DOKNR.:')+14,3.), BEST.);
> if index(_infile_,'DATO:') then AvskrDato =
> input(substr(_infile_,index(_infile_,'DATO:')+6), ddmmyy10.);
> if index(_infile_,'AVSKR. MÅTE:') then do;
> AvskrMaate = substr(_infile_,index(_infile_,'AVSKR. MÅTE:')+13);
> output;
> end;
> cards;
> -----------------------------------------------------------------------------------------------
> SAKSNR.: 1991/1
> ARKIV: RAPPORTARKIV
> TITTEL: GEOLOGICAL COMLETION REPORT PL 098 WELL 7120/10-2 NOVEMBER
> 1990
> SAKSDATO: 02.01.1991 SISTE DOK.: 02.01.1991 ANT.DOK: 1
> SANSV.: OD/ODH/KT
> DOKNR.: 1 JAVD: ODJ SBH: OD/ODH/K
> JDATO:02.01.1991 UOFF 5 A
> AVS/MOT: ESSO
> DOK.TITTEL: GEOLOGICAL COMLETION REPORT PL 098 WELL 7120/10-2
> AVSKR.DOKNR.: DATO: 02.01.1991
> AVSKR. MÅTE: X
> -----------------------------------------------------------------------------------------------
> SAKSNR.: 1991/2
> ARKIV: RAPORTARKIV NR 9
> TITTEL: RESERVOARTEKNISK RAPPORT STATFJORD NORD 1 EKS
> SAKSDATO: 02.01.1991 SISTE DOK.: 02.01.1991 ANT.DOK: 1
> SANSV.: OD/ODH/RO
> DOKNR.: 1 JAVD: ODJ SBH: OD/ODH/R
> JDATO:02.01.1991 UOFF FORTR
> AVS/MOT: OD-S
> DOK.TITTEL: RESERVOARTEKNISK RAPPORT STATFJORD NORD 1 EKS
> AVSKR.DOKNR.: 3 DATO: 02.01.1991
> AVSKR. MÅTE: X
> -----------------------------------------------------------------------------------------------
> run;
>
>
>
> Regards - Rune
>
>
>
>
> Jim Groeneveld wrote:
> > Hi Rune,
> >
> > Well, I think the following suggestions should remove your problems:
> >
> > Remove:
> > Antall_dok length = 3
> > Doknr length = 3
> > AvskrDoknr length = 3
> >
> > They may be a maximum of three digits, but you declare them to be 3 binary
> > bytes with which you can
> >
> > represent values up to 2^(3*8). By removing that code they will obtain the
> > standard length of 8 bytes.
> >
> > And I wonder where the compressed size actually is being applied: in
> > memory, in a dataset and/or in a
> >
> > compressed dataset.
> >
> > Change:
> > if index(_infile_,'ANT.DOK:') then Antall_dok =
> > substr(_infile_,index(_infile_,'ANT.DOK:')+9);
> > into:
> > if index(_infile_,'ANT.DOK:') then Antall_dok =
> > INPUT (
> > substr(_infile_,index(_infile_,'ANT.DOK:')+9,###),
> > BEST.);
> > where ### indicates the number of characters (where the digits are) to
> > read. In case you omit that the input function sees the whole remaining
> > string, including the tests after the digits and can't make anything of it.
> >
> > And do likewise with DokNr and AvskrDoknr. You may have thought that your
> > length statement for these variables limited their length in terms of
> > number of characters, but, as explained that is not true with numeric
> > variables. And I think that was your main problem.
> >
> > And in the future always try to avoid implicit type conversions. Things
> > may work differently than you might expect.
> >
> > Regards - Jim.
> > --
> > Jim Groeneveld, Netherlands
> > statistician, SAS consultant
> > home.hccnet.nl/jim.groeneveld
> >
> > On Tue, 27 Jun 2006 05:36:27 -0700, =?iso-8859-1?q?Rune_Runnest=F8?=
> > <rune@FASTLANE.NO> wrote:
> >
> > >Jim Groeneveld wrote:
> > >> Hi Rune,
> > >>
> > >> You defined DokNr, and Antall_dok and AvskrDoknr as well, as numeric,
> > >> while you interprete them as being character.
> > >
> > >I don't follow you here. Where do I treat those variables as being
> > >character ? And where do I treat Antall_dok and AvskrDoknr in another
> > >way then Doknr ? For the variables Antall_dok and AvskrDoknr, there is
> > >no values missing. That is, for AvskrDoknr the value is blank in the
> > >instream data file. But for Doknr, I don't see why it should be blank
> > >in the data set.
> > >
> > >See you log, you must have
> > >> many NOTES on implicit type conversion. You should take care to avoid
> > that
> > >> by using either all character variables (except for your date variables)
> > >> or by using the function INPUT to convert the character value (if
> > digits)
> > >> to numeric.
> > >
> > >I want the digits in Doknr, Antall_dok and AvskrDoknr to be
> > >right-justified, its' hard to get that without having the variables
> > >numeric. If I am not using the INPUT function right, could you make the
> > >necessary changes in the code visible for me ?
> > >
> > >>From you info I presume your DokNr data are not completely or
> > >> not at all digits and thus can not be (implicitly or explicitly)
> > converted
> > >> to numeric.
> > >
> > >The 2 occurences of Doknr are both digits (the digit '1')
> > >
> > >Your _INFILE_ data variable is character by definition.
> > >
> > >How does that affect the my code ?
> > >
> > >>
> > >> Regards - Jim.
> > >> --
> > >> Jim Groeneveld, Netherlands
> > >> statistician, SAS consultant
> > >> home.hccnet.nl/jim.groeneveld
> > >
> > >
> > >
> > >Regards, Rune
|