Hello!
Is it possible to specify the format ou data type when using proc import?
I have this code:
OPTIONS COMPRESS=BINARY REUSE=YES;
PROC IMPORT DATAFILE="&CAMINHO./&NOME_BASE..txt"
OUT=ARQUIVO (rename=Var1=RECORD_TYPE rename=Var2=COMPANY_CODE rename=Var3=POSTING_DATE rename=Var4=OPERATION_DATE rename=Var5=COST_CENTER
DBMS=DLM
REPLACE;
DELIMITER=';';
GETNAMES=NO;
GUESSINGROWS=3000000;
RUN;
My problem is that in my TXT file I have a text like 20181400000001358041 that SAS thinks that is a number so it displays 2,01814E+19 and when I use PUT() to change it back to text format, it changes the number to 20181400000001359872.
Can anyone tell me then how to set the import format or how to make SAS not modify my information?
Thank you!
You will need to write your own data step to read the file. It is trivial to do and I find usually easier than writing the PROC IMPORT code.
Especially if you actual have information from the provider of the file about what variables is contains and what type of data each variable stores.
So if you data just has the five variables mentioned in your code the data step might look like this:
data ARQUIVO ;
length RECORD_TYPE $20 COMPANY_CODE $20
POSTING_DATE 8 OPERATION_DATE 8 COST_CENTER $10
;
informat POSTING_DATE OPERATION_DATE yymmdd.;
format POSTING_DATE OPERATION_DATE yymmdd10.;
infile "&CAMINHO./&NOME_BASE..txt" dsd dlm=';' truncover;
input RECORD_TYPE -- COST_CENTER;
run;
You need to write a data step then, PROC IMPORT does not provide a way to specify variable types.
See example 4 (you don't have to pay to access, just close pop ups) or check the log after you run the PROC IMPORT and take the code there to customize. It has a lot of extra's but it can get you started.
If you only have a few variables it's easy to do, if you have a few hundred its a pain but there are other methods.
@FADUVIGA wrote:
Hello!
Is it possible to specify the format ou data type when using proc import?
I have this code:
OPTIONS COMPRESS=BINARY REUSE=YES;
PROC IMPORT DATAFILE="&CAMINHO./&NOME_BASE..txt"
OUT=ARQUIVO (rename=Var1=RECORD_TYPE rename=Var2=COMPANY_CODE rename=Var3=POSTING_DATE rename=Var4=OPERATION_DATE rename=Var5=COST_CENTER
DBMS=DLM
REPLACE;
DELIMITER=';';
GETNAMES=NO;
GUESSINGROWS=3000000;
RUN;
My problem is that in my TXT file I have a text like 20181400000001358041 that SAS thinks that is a number so it displays 2,01814E+19 and when I use PUT() to change it back to text format, it changes the number to 20181400000001359872.
Can anyone tell me then how to set the import format or how to make SAS not modify my information?
Thank you!
GUESSINGROWS=MAX ;
@Ksharp wrote:
GUESSINGROWS=MAX ;
That will not help for this problem. Proc import is not smart enough to check whether a column that looks like numbers actually contains digit strings with too many digits for SAS to store exactly as a number.
You will need to write your own data step to read the file. It is trivial to do and I find usually easier than writing the PROC IMPORT code.
Especially if you actual have information from the provider of the file about what variables is contains and what type of data each variable stores.
So if you data just has the five variables mentioned in your code the data step might look like this:
data ARQUIVO ;
length RECORD_TYPE $20 COMPANY_CODE $20
POSTING_DATE 8 OPERATION_DATE 8 COST_CENTER $10
;
informat POSTING_DATE OPERATION_DATE yymmdd.;
format POSTING_DATE OPERATION_DATE yymmdd10.;
infile "&CAMINHO./&NOME_BASE..txt" dsd dlm=';' truncover;
input RECORD_TYPE -- COST_CENTER;
run;
Thank you very much! That is what I needed!!
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.