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.
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.
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;
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.
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;
Thank you very much, Tom! It helped and of course this is not a script, this is a program!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.