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

Hi,

I have a txt file with all my observation in just one record, similiar to this:

[{"Var1":"a1234","Var2":"a567","var3":0,"var4":0},{"Var1":"b1234","Var2":"b567","var3":1,"var4":0},{"Var1":"c1234","Var2":"c567","var3":0,"var4":0}, ..............................................]

I'm trying to import its content to a dataset. But even using double trailing I just end up with 2 observations (the txt file has something about 20,000 observations). This is the code:

data dataset1;

  infile '/local/arquivo_1.txt' dlm='{[,:"} ;';

  input var1 $ Var1_content : $9. var2 : $12. Var2_content : $12. var3 : $16.  Var3_content $ var4 : $12. Var4_content $ @@;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Add a LRECL option to the INFILE statement.  You should be able to set it to a billion (1 with 9 zeros).

If that doesn't work then read the file using STREAM input and convert all of the '}' to '0A'x and then the line lengths will be shorter.

View solution in original post

6 REPLIES 6
Tom
Super User Tom
Super User

Add a LRECL option to the INFILE statement.  You should be able to set it to a billion (1 with 9 zeros).

If that doesn't work then read the file using STREAM input and convert all of the '}' to '0A'x and then the line lengths will be shorter.

TanaraRose
Calcite | Level 5

Thank you very much Tom! It worked perfectly

ballardw
Super User

If this was a one-time project I would be very tempted to use and editor to replace the string },

with }<new line> where new line is the appropriate one for your OS.

Peter_C
Rhodochrosite | Level 12

data dataset1;

  infile '/local/arquivo_1.txt' dlm='{[,:"} ;';

length varn varn_conts $20 ;

Do case = 1 by 1 ;

  input varn Varn_conts @ ;

  If varn = " " then input ;

  Else output ;

End ;

stop ;

run;

Ksharp
Super User

It is JSON file which is a stream file , You need to tell SAS it is a stream file by defining recfm=n ;

data dataset1;

  infile '/local/arquivo_1.txt' dlm='{[,:"} ;'    recfm=n   ;

  input var1 $ Var1_content : $9. var2 : $12. Var2_content : $12. var3 : $16.  Var3_content $ var4 : $12. Var4_content $ @@;

run;

Xia Keshan

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 6 replies
  • 1915 views
  • 5 likes
  • 6 in conversation