BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
V_Andy
Fluorite | Level 6

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

2 REPLIES 2
Tom
Super User Tom
Super User

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;


V_Andy
Fluorite | Level 6

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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