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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1033 views
  • 5 likes
  • 6 in conversation