Are there other words in the series? Please make sure the sample is representative of your actual data.
Are there other words in the series? Please make sure the sample is representative of your actual data.
If read in as raw dump, you could also try:
filename FT15F001 temp lrecl=512;
data test;
infile FT15F001 truncover scanover ;
input @"Atmbarcode " +3 var $10. @@;
parmcards4;
"Atmbarcode ":"CA74822531", Atmbarcode ":"AZ74822531", Atmbarcode ":"WA74822531",
;;;;
run;
filename ft15f001 clear ;
I definitely don't think mine is the correct answer.
Also, I could have sworn you asked this question once already and received several solutions....
Ok.
As I mentioned before, how close is this to your exact data.
Post several records that show the variation in your data. If it's ALL structured the way you've specified, you can use SCAN and a do loop to extract all the records.
Hate to repeat myself but...
Post several records that show the variation in your data.
Also, is the original file JSON or XML? It looks sort of like that format.
So this is row 1 of your CSV file?
Please explain your data?
Maybe you should post a small sample of the file.
Make sure to include multiple lines and all other fields.
And save the CSV as a txt file to attach it.
Here's a tested version:
data have;
length field $2000.;
informat field $2000.;
field='{"row":1,"bagbarcode ":"RS5748008","Atmbarcode ":"CA0797220129","$$HASHKEY":"object:14"},{"row":1,"bagbarcode ":"RS5748009","Atmbarcode ":"TX797220129","$$HASHKEY":"object:14"},row":1,"bagbarcode ":"RS5748015","Atmbarcode ":"WV0797220129","$$HASHKEY":"object:14"},{"row":1,"bagbarcode ":"RS5748029","Atmbarcode ":"SA97220129","$$HASHKEY":"object:14"},row":1,"bagbarcode ":"RS5748028","Atmbarcode ":"CA0797220129","$$HASHKEY":"object:14"},{"row":1,"bagbarcode ":"RS57480259","Atmbarcode ":"JQ797220129","$$HASHKEY":"object:14"},row":1,"bagbarcode ":"RS5748039","Atmbarcode ":"NY0797220129","$$HASHKEY":"object:14"},{"row":1,"bagbarcode ":"RS5748038","Atmbarcode ":"QU97220129","$$HASHKEY":"object:14"},row":1,"bagbarcode ":"RS5748048","Atmbarcode ":"UT0797220129","$$HASHKEY":"object:14"},{"row":1,"bagbarcode ":"RS5748048","Atmbarcode ":"DA97220129","$$HASHKEY":"object:14"},row":1,"bagbarcode ":"RS5748058","Atmbarcode ":"DF797220129","$$HASHKEY":"object:14"},{"row":1,"bagbarcode ":"RS5748016","Atmbarcode ":"JX797220129","$$HASHKEY":"object:14"},row":1,"bagbarcode ":"RS57480017","Atmbarcode ":"QA0797220118","$$HASHKEY":"object:14"},{"row":1,"bagbarcode ":"RS5748019","Atmbarcode ":"FL797220129","$$HASHKEY":"object:14"}, row":1,"bagbarcode ":"RS5748012","Atmbarcode ":"LA0797220129","$$HASHKEY":"object:14"},{"row":1,"bagbarcode ":"RS5748011","Atmbarcode ":"WA797220129","$$HASHKEY":"object:14"}';
run;
data want;
set have;
*Number of key-value pairs;
x=countw(field, ",");
*Loop over pairs;
do i=1 to x;
*Get the key-value pair;
code=scan(field, i, ",");
*Search for code of interest;
if find(code, 'Atmbarcode')>0 then
do;
*Extract components required;
key=compress(scan(code, 1, ":"), '"');
value=compress(scan(code, 2, ":"), '"');
*Print results to data set;
output;
end;
end;
keep key value;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: