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;
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.
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.
Thank you very much Tom! It worked perfectly
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.
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;
Is the original file JSON?
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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.