<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to get every instance of a word  ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306610#M65590</link>
    <description>&lt;P&gt;Maybe you should post a small sample of the file.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make sure to include multiple lines and all other fields.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And save the CSV as a txt file to attach it.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 23 Oct 2016 03:26:36 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-10-23T03:26:36Z</dc:date>
    <item>
      <title>How to get every instance of a word  ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306346#M65489</link>
      <description>Hi have a data dump that has a special word in the comment field I need to extract every instance.&lt;BR /&gt;&lt;BR /&gt;Here is the script that I was using&lt;BR /&gt;&lt;BR /&gt;Data have;&lt;BR /&gt;Infile 'C:\users\desktop \night4.csv' dlm ='09' X truncover;&lt;BR /&gt;Input x $25000.;&lt;BR /&gt;Length Bacode $25;&lt;BR /&gt;N+1;&lt;BR /&gt;Pid=prxparse ('/atmbarcode:\W*\w+/i');&lt;BR /&gt;s=1;&lt;BR /&gt;E=length (x);&lt;BR /&gt;Call prxnet (pid,s,e,x ,p,l);&lt;BR /&gt;Do while (p&amp;gt;0);&lt;BR /&gt;Bacode =substr (x,p,l);&lt;BR /&gt;Output;&lt;BR /&gt;Call prxnext (pid,s,e x,p,l);&lt;BR /&gt;End;&lt;BR /&gt;Keep n x bacode;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;Here is the data it's 3 cols&lt;BR /&gt;&lt;BR /&gt;A&lt;BR /&gt;"Atmbarcode ":"CA74822531", Atmbarcode ":"AZ74822531", Atmbarcode ":"WA74822531", ... Everytime there is a atmbarcode I need the 10 characters to be extract ...&lt;BR /&gt;Out put&lt;BR /&gt;X&lt;BR /&gt;AZ74822531&lt;BR /&gt;WA74822531&lt;BR /&gt;CA74822531&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 21 Oct 2016 16:09:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306346#M65489</guid>
      <dc:creator>Beto16</dc:creator>
      <dc:date>2016-10-21T16:09:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to get every instance of a word  ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306395#M65504</link>
      <description>&lt;P&gt;&amp;nbsp;Are there other words in the series? Please make sure the sample is representative of your actual data.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2016 17:41:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306395#M65504</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-21T17:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to get every instance of a word  ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306404#M65506</link>
      <description>&lt;P&gt;If read in as raw dump, you could also try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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 ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Oct 2016 18:20:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306404#M65506</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2016-10-21T18:20:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to get every instance of a word  ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306415#M65509</link>
      <description>How do I refer a file? (Named test1)&lt;BR /&gt;And the col where the data is located it's called x ?</description>
      <pubDate>Fri, 21 Oct 2016 19:09:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306415#M65509</guid>
      <dc:creator>Beto16</dc:creator>
      <dc:date>2016-10-21T19:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to get every instance of a word  ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306421#M65512</link>
      <description>&lt;P&gt;I definitely don't think mine is the correct answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, I could have sworn you asked this question once already and received several solutions....&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2016 19:25:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306421#M65512</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-21T19:25:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to get every instance of a word  ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306427#M65514</link>
      <description>Yes I did but the raw data change before I had 100 col to extract an now the data is in one cell which could have 10 to 20 I'd I would need to extract... the solution I was giving doesn't work anymore</description>
      <pubDate>Fri, 21 Oct 2016 19:48:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306427#M65514</guid>
      <dc:creator>Beto16</dc:creator>
      <dc:date>2016-10-21T19:48:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to get every instance of a word  ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306432#M65515</link>
      <description>&lt;P&gt;Ok.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As I mentioned before, how close is this to your exact data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2016 20:00:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306432#M65515</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-21T20:00:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to get every instance of a word  ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306568#M65562</link>
      <description>the data looks&lt;BR /&gt;[{"row":1,"bagbarcode ":"RS5748008","Atmbarcode ":"CA0797220129","$$HASHKEY":"object:14"},{"row":1,"bagbarcode ":"RS5748009","Atmbarcode ":"TX797220129","$$HASHKEY":"object:14"}] this is in one cell sometimes there can be 10 entries in that cell I need data to look&lt;BR /&gt;Output&lt;BR /&gt;A. B&lt;BR /&gt;TX797220129. RS5748008&lt;BR /&gt;CA797220129. RS5748009</description>
      <pubDate>Sat, 22 Oct 2016 18:01:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306568#M65562</guid>
      <dc:creator>Beto16</dc:creator>
      <dc:date>2016-10-22T18:01:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to get every instance of a word  ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306574#M65565</link>
      <description>&lt;P&gt;Hate to repeat myself but...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Post several records that show the variation in your data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, is the original file JSON or XML? It looks sort of like that format.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Oct 2016 21:45:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306574#M65565</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-22T21:45:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to get every instance of a word  ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306606#M65586</link>
      <description>The file comes in as a check csv. I open thru excel ..&lt;BR /&gt;&lt;BR /&gt;Row 1&lt;BR /&gt;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"}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This is an example of my raw data .. I would need help with setting up a scan with loop ..thank you</description>
      <pubDate>Sun, 23 Oct 2016 03:07:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306606#M65586</guid>
      <dc:creator>Beto16</dc:creator>
      <dc:date>2016-10-23T03:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to get every instance of a word  ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306607#M65587</link>
      <description>&lt;P&gt;So this is row 1 of your CSV file?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please explain your data?&lt;/P&gt;</description>
      <pubDate>Sun, 23 Oct 2016 03:11:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306607#M65587</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-23T03:11:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to get every instance of a word  ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306608#M65588</link>
      <description>The data is in one cell BUT data is format like this&lt;BR /&gt;&lt;BR /&gt;Raw data. Date. Id&lt;BR /&gt;Raw data. 10/01/16. 1ZR67&lt;BR /&gt;&lt;BR /&gt;RAW DATA 10/06/16. 1ZR68&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sun, 23 Oct 2016 03:17:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306608#M65588</guid>
      <dc:creator>Beto16</dc:creator>
      <dc:date>2016-10-23T03:17:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to get every instance of a word  ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306610#M65590</link>
      <description>&lt;P&gt;Maybe you should post a small sample of the file.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make sure to include multiple lines and all other fields.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And save the CSV as a txt file to attach it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Oct 2016 03:26:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306610#M65590</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-23T03:26:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to get every instance of a word  ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306620#M65594</link>
      <description>&lt;P&gt;Here's a tested version:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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')&amp;gt;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Oct 2016 05:21:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-every-instance-of-a-word/m-p/306620#M65594</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-23T05:21:47Z</dc:date>
    </item>
  </channel>
</rss>

