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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

5 REPLIES 5
Reeza
Super User

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!


 

Ksharp
Super User

GUESSINGROWS=MAX ;

Tom
Super User Tom
Super User

@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.

Tom
Super User Tom
Super User

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;
FADUVIGA
Calcite | Level 5

Thank you very much! That is what I needed!!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 5516 views
  • 2 likes
  • 4 in conversation