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

Hello Experts,

 

I can't import the txt file. Do I need to add some options please? I attached the file TEST.txt. My code is: 


    data test;
	ifile "&Rep.\TEST.txt" dsd dlm="" missover firstobs=1;
	informat A $20.;
	informat B $20.;
	informat C $20.;
	informat D $20.;
	informat F $20.;
	informat G $20.;
	informat H $20.;
	informat I $20.;
	informat J $20.;
	informat K $20.;
	format A $20.;
	format B $20.;
	format C $20.;
	format D $20.;
	format F $20.;
	format G $20.;
	format H $20.;
	format I $20.;
	format J $20.;
	format K $20.;
	input A B C D E F G H I J K;
	run;

 

Thank you for your help! 

Best regards,

Marie

1 ACCEPTED SOLUTION

Accepted Solutions
RichardDeVen
Barite | Level 11

Examining the data a 'just' values you have a number of space separated values, but I think some of the actual data you want contain spaces. The data file appears to have a fixed layout and you can use that feature of the data during input.

 

The INPUT statement has a column pointer control feature ($ <start-column> - <end-column >) that lets you specify exactly where in a line a data value should be read from.

 

Consider (speculated field name under data characters)

0118829    75416EUR2 02601198001  031220AG2R LA SUCURSAL CASH                             0000000812191H0000            
AAAAAAAAAA BBBBBBBBB CCCCCCCCCCCC DDDDDDEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE FFFFFFFFFFFFFFFFFF
----|----10---|----20---|----30---|----40---|----50---|----60---|----70---|----80---|----90---|----100--|----110--|---- ruler

Fixed layout input

INPUT A $1-10 B $12-20 C $22-33 D $35-40 E $41-89 F $ 91-108;

With an INPUT statement with such syntax you will not need FORMAT or INFORMAT or LENGTH statements.

View solution in original post

4 REPLIES 4
RichardDeVen
Barite | Level 11

Examining the data a 'just' values you have a number of space separated values, but I think some of the actual data you want contain spaces. The data file appears to have a fixed layout and you can use that feature of the data during input.

 

The INPUT statement has a column pointer control feature ($ <start-column> - <end-column >) that lets you specify exactly where in a line a data value should be read from.

 

Consider (speculated field name under data characters)

0118829    75416EUR2 02601198001  031220AG2R LA SUCURSAL CASH                             0000000812191H0000            
AAAAAAAAAA BBBBBBBBB CCCCCCCCCCCC DDDDDDEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE FFFFFFFFFFFFFFFFFF
----|----10---|----20---|----30---|----40---|----50---|----60---|----70---|----80---|----90---|----100--|----110--|---- ruler

Fixed layout input

INPUT A $1-10 B $12-20 C $22-33 D $35-40 E $41-89 F $ 91-108;

With an INPUT statement with such syntax you will not need FORMAT or INFORMAT or LENGTH statements.

Kurt_Bremser
Super User

That file has fixed column widths, so you can use formatted INPUT or INPUT with positions:

0118829    75416EUR2 02601198001  031220AG2R LA SUCURSAL CASH                             0000000812191H0000            
0718829    75416EUR2 02601198001  041220                                                  0000000812191H                
0118829    75416EUR2 02601198040  031220AG2R LA SUCURSAL CASH                             0000000012000{0000            
0718829    75416EUR2 02601198040  041220                                                  0000000012000{                
0118829    75416EUR2 03426263540  031220AG2R SEUNICA PREVOYANCE                           0000000082281J0000            
0718829    75416EUR2 03426263540  041220                                                  0000000082281J                
0118829    75416EUR2 03426263541  031220AG2R SEUNICA PREVOYANCE                           0000000140616B0000            
0718829    75416EUR2 03426263541  041220                                                  0000000140616B                
0118829    75416EUR2 04894145101  031220LA SUCURSAL                                       0000001177397B0000            
0718829    75416EUR2 04894145101  041220                                                  0000001177397B                
0118829    75416EUR2 04894145140  031220LA SUCURSAL                                       0000000009508I0000            
0718829    75416EUR2 04894145140  041220                                                  0000000009508I                
0118829    75416EUR2 02601198001  041220AG2R LA SUCURSAL CASH                             0000000812191H0000            
0718829    75416EUR2 02601198001  051220                                                  0000000812191H                
0118829    75416EUR2 02601198040  041220AG2R LA SUCURSAL CASH                             0000000012000{0000            
0718829    75416EUR2 02601198040  051220                                                  0000000012000{                
0118829    75416EUR2 03426263540  041220AG2R SEUNICA PREVOYANCE                           0000000082281J0000            
0718829    75416EUR2 03426263540  051220                                                  0000000082281J                
0118829    75416EUR2 03426263541  041220AG2R SEUNICA PREVOYANCE                           0000000140616B0000            
0718829    75416EUR2 03426263541  051220                                                  0000000140616B                
0118829    75416EUR2 04894145101  041220LA SUCURSAL                                       0000001177397B0000            
0718829    75416EUR2 04894145101  051220                                                  0000001177397B                
0118829    75416EUR2 04894145140  041220LA SUCURSAL                                       0000000009508I0000            
0718829    75416EUR2 04894145140  051220                                                  0000000009508I                
ballardw
Super User

"Can't import" is awful vague.

Are there errors in the log?: Post the code and log in a code box opened with the <> to maintain formatting of error messages.

No output? Post any log in a code box.

Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the <> icon or attached as text to show exactly what you have and that we can test code against.

 

You should describe why you think you "can't import".

 

One thing likely related: when you have an input statement like

input a b c d e f g h i;

then you are using List input. Spaces between values will indicate start and end of the value. So when your file looks like

0118829    75416EUR2 02601198001  031220AG2R LA SUCURSAL CASH                             0000000812191H0000            

0718829    75416EUR2 02601198001  041220                                                  0000000812191H  

then each of LA, SUCURSAL and CASH will be E, F and G variables. On the second line, because of the spaces  0000000812191H will be the value for E.

 

If you need to read a specific variable starting at a specific column you need to indicate such and use a different form of the Input statement to force reading to include spaces in the values if that is the problem.

Maybe this will get you started for an input statement:

input @1 a $11. @12 b $10. @22 c $13. @35 d $12. 
      @46 e $20. ;

The @ indicates the column number to move an input pointer to and then to start reading the variable. The informats I chose for the first columns shouldn't attempt to read values from the next variables for the first values. I doubt that your documentation on this data source says each variable should contain 20 columns. I'm not sure how long E should be and maybe should be longer than 20. For the stuff after that without documentation I don't know where breaks might be needed because the last bit of text on the lines seems to indicate that there may be two or more separate values without always a space.

 

 

 

kbauphealth20
Fluorite | Level 6

I'm curious if it's a simple typo.

 

You put "ifile" in your code instead of "infile".

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 5281 views
  • 4 likes
  • 5 in conversation