DATA Step, Macro, Functions and more

Script import problems

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 13
Accepted Solution

Script import problems

Hi everyone!

I got a problem trying to imprort data from .tsv text file to SAS Base. I used the script in one of the previous versions and everything was okay but now when I got SAS 9.4 I get an odd result.

The initial source of data is text file with only one column. Here is a sample of data file:

TRANS_SUM
2286,5
985,39
3730,23
984,12

To import data I submit the script below:

Data TRANS.Test_data (Compress = yes);

  Retain TRANS_SUM;

   Infile 'h:\sample2.tsv'

   DLM = '09'x MISSOVER DSD FIRSTOBS = 2;

   Input

  TRANS_SUM_RUR CommaX20.;

   Format

  TRANS_SUM_RUR Comma20.2;

Run;

Earlier I got a dataset with one column and for records of decimal numbers with decimal part separated by comma.

TRANS_SUM
2286.5
985.39
3730.23
984.12

But now a dataset is being created but I get missing values instead.

TRANS_SUM
.
.
.
.

Would you be so king to explain me what's wrong with the script.


Accepted Solutions
Solution
‎07-18-2015 07:52 PM
Super User
Super User
Posts: 6,502

Re: Script import problems

First, why would you use the MISSOVER option instead of the TRUNCOVER option?  The only difference is that with MISSOVER if you try to read 20 characters and there are 6 available then SAS sets the value to missing. With TRUNOVER is just reads the 6 characters that are there.

Second don't use formatted input when the widths of the fields vary (at least not without adding : or other modifiers) to prevent SAS from reading past the end of the field and getting the column pointer confused.

Third SAS code files are called programs not scripts.  SAS is a language not a shell. Smiley Happy

data trans.test_data (compress = yes);

   infile 'h:\sample2.tsv'

      dlm = '09'x truncover dsd firstobs = 2

   ;

   informat trans_sum_rur commax20.;

   format trans_sum_rur comma20.2;

   input trans_sum_rur ;

run;


View solution in original post


All Replies
Solution
‎07-18-2015 07:52 PM
Super User
Super User
Posts: 6,502

Re: Script import problems

First, why would you use the MISSOVER option instead of the TRUNCOVER option?  The only difference is that with MISSOVER if you try to read 20 characters and there are 6 available then SAS sets the value to missing. With TRUNOVER is just reads the 6 characters that are there.

Second don't use formatted input when the widths of the fields vary (at least not without adding : or other modifiers) to prevent SAS from reading past the end of the field and getting the column pointer confused.

Third SAS code files are called programs not scripts.  SAS is a language not a shell. Smiley Happy

data trans.test_data (compress = yes);

   infile 'h:\sample2.tsv'

      dlm = '09'x truncover dsd firstobs = 2

   ;

   informat trans_sum_rur commax20.;

   format trans_sum_rur comma20.2;

   input trans_sum_rur ;

run;


Occasional Contributor
Posts: 13

Re: Script import problems

Thank you very much, Tom! It helped and of course this is not a script, this is a program!

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 211 views
  • 0 likes
  • 2 in conversation