Sas infile dataline truckctuates with 8 characters

After not working with SAS for several years, I am trying to get back to it ...

I am trying to read comma delimited data. Although there are many examples, I cannot get the following to import my data correctly:

data h0;
   infile datalines delimiter=','; 
   input
   kst
   kst_bez $
   hx $
   hx_bez $
   hxx $
   hxx_bez $
   hxxx $
   hxxx_bez $
;
   datalines;
10000,Team 1 South,H0,Group,H10,Retail,H112,Retail Germany
10001,Team 2 North & West,H0,H10,Retail Division 2,H112,Retail Germany
10003,Human Res,H0,Group,H20,HR,H112,HR Germany
;

      

I would have thought it was delimiter=','

telling SAS to just read the data between my ,

-Characters into something like VARCHAR

-variable ... however any alphanumeric data is truncated at 8 characters.

I vaguely remember that I need to use something like $varying40.

that matches the examples I gave. However, if I add this to my variables, the variable does not stop at ,

, but instead reads an integer, say 40 characters.

Any hints?

Thanks a ton!

+3


source to share


1 answer


Unless you define them otherwise, SAS will by default use all character variables up to length 8. It is probably clearer for you and the SAS compiler if you explicitly define variables with a statement LENGTH

or ATTRIB

before using them, otherwise SAS has to guess how you wanted them to be defined based on how they were first used.

data h0;
  length kst 8 kst_bez $20 hx $20 hx_bez $20 hxx $20 hxx_bez $20 
         hxxx $20 hxxx_bez $20
  ;
  infile datalines dsd truncover ;
  input kst -- hxxx_bez ;
datalines;
...

      



You can add the in-line informat specification to the INPUT statement as the first use of the variable, and SAS will default to the width of the used information file, but remember to add the colon prefix to prevent SAS from reading through delimiters.

data h0;
  infile datalines dsd truncover ;
  input kst kst_bez :$20. hx :$20. hx_bez :$20. hxx :$20. hxx_bez :$20. 
        hxxx :$20. hxxx_bez :$20.
  ;
datalines;
...

      

+4


source







All Articles