Desktop productivity for business analysts and programmers

Importation crops last variable for no apparent reason

Accepted Solution Solved
Reply
Contributor
Posts: 46
Accepted Solution

Importation crops last variable for no apparent reason

I'm on SAS version 5.1.

 

I'm trying to import a text file into SAS. Using SAS Guide everything works fine.

 

Using the code generated by this importation, almost everything is fine. The last variable, however, is cropped. It's supposed to be a three digit number, but after the imporation I get a single digit.

 

Here's a sample of the code I'm using (I greatly reduced the number of variables which I suppose is only chaff).

 

DATA WORK.Output;
    LENGTH
        Var1            8
	Var2            8 ;
    FORMAT
        Var1        BEST12.
	Var2        BEST3. ;
    INFORMAT
        Var1        BEST12.
	Var2        BEST3. ;
    INFILE "Path"
 	LRECL=324
    DLM=':'
    MISSOVER
    DSD ;

    INPUT
        Var1        : ?? BEST12.
	Var2        : ?? BEST3. ;
RUN;

 

Any clues about what's happening? How can I fix this?

 

Thanks.


Accepted Solutions
Solution
‎07-13-2016 08:41 AM
Super User
Super User
Posts: 7,720

Re: Importation crops last variable for no apparent reason

Hi,

 

I imagine you mean you are using EG 5.1 (SAS is currently at 9.4).  It is likely to be this line:

LRECL=324

Which limits the characters per line to 324, any reason why you put this in, most of the time I would leave it out or set to 32767.

 

Also some tips:

Why are you using a : as a delimiter?  Comma would be the normal, but occasionally pipe could be used.  Seems odd.

Why read in variables with ?? - this just seems like you don't know what data is going to come in?

 

No need to code all in uppercase - its quite hard to read, and use spaces to indent rather than tabs which render differently between applications.

So your code could be written as:

data work.output;
length var1 var2 8;
format var1 best12. var2 best3.;
informat var1 best12. var2 best3.;
infile "path" lrecl=32767 dlm=':' missover dsd;
input var1 var2;
run;

View solution in original post


All Replies
Solution
‎07-13-2016 08:41 AM
Super User
Super User
Posts: 7,720

Re: Importation crops last variable for no apparent reason

Hi,

 

I imagine you mean you are using EG 5.1 (SAS is currently at 9.4).  It is likely to be this line:

LRECL=324

Which limits the characters per line to 324, any reason why you put this in, most of the time I would leave it out or set to 32767.

 

Also some tips:

Why are you using a : as a delimiter?  Comma would be the normal, but occasionally pipe could be used.  Seems odd.

Why read in variables with ?? - this just seems like you don't know what data is going to come in?

 

No need to code all in uppercase - its quite hard to read, and use spaces to indent rather than tabs which render differently between applications.

So your code could be written as:

data work.output;
length var1 var2 8;
format var1 best12. var2 best3.;
informat var1 best12. var2 best3.;
infile "path" lrecl=32767 dlm=':' missover dsd;
input var1 var2;
run;
Contributor
Posts: 46

Re: Importation crops last variable for no apparent reason

Yes, I'm using SAS EG 5.1, I'm really not aware of the different SAS that exist, hence the misinformation. Thanks.

 

You got it right, it's exactly the LRECL parameter that was screwing things up. I had it at 324 because that's what the generated code had in it.

 

I use : as a delimiter because that's what people use around here (at work). I wasn't aware that commas are more conventional, but I really can't see how that matters.

 

The ?? are there because, again, the generated code had it too. As you can guess, I don't know what I'm doing. I'm learning by seeing examples.

 

Thanks for all the tips and the answer.

Super User
Super User
Posts: 7,720

Re: Importation crops last variable for no apparent reason

[ Edited ]

Just to add, Comma Separated Variable files - whilst officially documented as a standard - is widely used around the world for data transfer.  If you open a CSV in Excel it will automatically populate values into columns for instance.  The : is used in different ways for different applications, and so could be confusing.  Its fine if its just within your company, unless anyone new joins, but going outside...

 

https://en.wikipedia.org/wiki/Comma-separated_values

Respected Advisor
Posts: 3,788

Re: Importation crops last variable for no apparent reason

Your problem is likely related to TERMSTR

http://support.sas.com/kb/14/178.html

 

SAS is probably reading CR '0d'x as the last character in field 2, which is not valid in a number field.  Your use of ?? to suppress the associated messages are preventing you from seeing what is happening.

 

Try adding TERMSTR=CRLF on the INFILE statement.

Contributor
Posts: 46

Re: Importation crops last variable for no apparent reason

Actually I did try that, but it didn't work.

The DLM SAS generated was '7F'x though, not CR '0d'x, if that matters.

 

Thanks.

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 319 views
  • 0 likes
  • 3 in conversation