<?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: Creating variables by extracting data from a long string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-variables-by-extracting-data-from-a-long-string/m-p/692223#M210825</link>
    <description>&lt;P&gt;Thank you! This worked!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Oct 2020 20:13:38 GMT</pubDate>
    <dc:creator>monali</dc:creator>
    <dc:date>2020-10-16T20:13:38Z</dc:date>
    <item>
      <title>Creating variables by extracting data from a long string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-variables-by-extracting-data-from-a-long-string/m-p/692183#M210805</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a field in the data table that looks like following. I want to extract patient data such as fullUrl, fgiven name, family name, gender, birth date etc. from this string and create variables. Can someone please assist with this? The source data table has thousands of rows so looking for an efficient way to extract these data. Thanks!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"{""fullUrl"": ""urn:uuid:XXXXX-XXXX-XXXX-XXX-XXXXXXXXXX"",&lt;BR /&gt;""resource"": {""meta"":&lt;BR /&gt;{""profile"": [""WEB-URL""]},&lt;BR /&gt;""name"": [{""use"": ""usual"", ""text"": ""FTest LTest"", ""given"": [""FTest""],&lt;BR /&gt;""family"": ""LTest""}], ""gender"": ""male"", ""address"": [{""use"": ""home"",&lt;BR /&gt;""city"": ""TestSt"", ""line"": [""ST ADDRESS""], ""state"": ""XX"",&lt;BR /&gt;""country"": ""US"", ""postalCode"": ""99999""}], ""telecom"": [{""use"":&lt;BR /&gt;""work"", ""value"": ""1234567890"", ""system"": ""phone""}], ""birthDate"":&lt;BR /&gt;""9999-99-99T99:99:99"", ""identifier"": [{""value"": ""1234"", ""system"":&lt;BR /&gt;""urn:oid:1.23.456.7.99999999.2.0000""}], ""resourceType"": ""Patient""}}"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2020 17:22:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-variables-by-extracting-data-from-a-long-string/m-p/692183#M210805</guid>
      <dc:creator>monali</dc:creator>
      <dc:date>2020-10-16T17:22:48Z</dc:date>
    </item>
    <item>
      <title>Re: Creating variables by extracting data from a long string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-variables-by-extracting-data-from-a-long-string/m-p/692195#M210813</link>
      <description>Is it by chance a JSON or XML file? If so, there's libname approaches to parse the data rather than manually parsing it.</description>
      <pubDate>Fri, 16 Oct 2020 17:51:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-variables-by-extracting-data-from-a-long-string/m-p/692195#M210813</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-10-16T17:51:24Z</dc:date>
    </item>
    <item>
      <title>Re: Creating variables by extracting data from a long string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-variables-by-extracting-data-from-a-long-string/m-p/692214#M210818</link>
      <description>&lt;P&gt;Any wanted variable is preceded in the input text with appropriate string followed by a colon ":", the value and closed with any combination of the delimiters: ']},";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;without having the input file type, next tested code can be expanded to read all wanted variables:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
  retain line;
  length text $100 line $1000;
  infile cards truncover;
  input text $100. @;
  line = cats(line,text) ;
  if index(text,'}}') then do; output; input; line=' '; end;
  keep line;
cards;
"{""fullUrl"": ""urn:uuid:XXXXX-XXXX-XXXX-XXX-XXXXXXXXXX"",
""resource"": {""meta"":
{""profile"": [""WEB-URL""]},
""name"": [{""use"": ""usual"", ""text"": ""FTest LTest"", ""given"": [""FTest""],
""family"": ""LTest""}], ""gender"": ""male"", ""address"": [{""use"": ""home"",
""city"": ""TestSt"", ""line"": [""ST ADDRESS""], ""state"": ""XX"",
""country"": ""US"", ""postalCode"": ""99999""}], ""telecom"": [{""use"":
""work"", ""value"": ""1234567890"", ""system"": ""phone""}], ""birthDate"":
""9999-99-99T99:99:99"", ""identifier"": [{""value"": ""1234"", ""system"":
""urn:oid:1.23.456.7.99999999.2.0000""}], ""resourceType"": ""Patient""}}"
; run;

%macro chk(str,var);
    %if &amp;amp;var EQ %then %let var = &amp;amp;str;
    ix = index(new_line,"&amp;amp;str"); 
    if ix&amp;gt;0 then &amp;amp;var = scan(substr(new_line,ix),2,':},');
%mend;
data b;
 set a;
     length name $30 family $30 gender $8 birth_date $25 new_line $1000;
     retain name family gender birth_date;
     array ch {*} name family gender birth_date;
     if _N_=1 then call missing(of ch(*));
     new_line = compress(line,'"[]');
     drop line ix new_line;
     
     %chk(given,name);
     %chk(family);
     %chk(gender);
     %chk(birthDate,birth_date);
run;
 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2020 19:30:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-variables-by-extracting-data-from-a-long-string/m-p/692214#M210818</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-10-16T19:30:33Z</dc:date>
    </item>
    <item>
      <title>Re: Creating variables by extracting data from a long string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-variables-by-extracting-data-from-a-long-string/m-p/692218#M210821</link>
      <description>&lt;P&gt;Thanks. It's a postgres database. The original data feeds are XML files but I am working with Postgres.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2020 19:56:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-variables-by-extracting-data-from-a-long-string/m-p/692218#M210821</guid>
      <dc:creator>monali</dc:creator>
      <dc:date>2020-10-16T19:56:19Z</dc:date>
    </item>
    <item>
      <title>Re: Creating variables by extracting data from a long string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-variables-by-extracting-data-from-a-long-string/m-p/692219#M210822</link>
      <description>&lt;P&gt;You may find interest in next link:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://groups.google.com/g/comp.soft-sys.sas/c/qqm_12q8hTA?pli=1" target="_self"&gt;https://groups.google.com/g/comp.soft-sys.sas/c/qqm_12q8hTA?pli=1&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2020 20:02:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-variables-by-extracting-data-from-a-long-string/m-p/692219#M210822</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-10-16T20:02:14Z</dc:date>
    </item>
    <item>
      <title>Re: Creating variables by extracting data from a long string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-variables-by-extracting-data-from-a-long-string/m-p/692223#M210825</link>
      <description>&lt;P&gt;Thank you! This worked!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Oct 2020 20:13:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-variables-by-extracting-data-from-a-long-string/m-p/692223#M210825</guid>
      <dc:creator>monali</dc:creator>
      <dc:date>2020-10-16T20:13:38Z</dc:date>
    </item>
  </channel>
</rss>

