<?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: Character functions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Character-functions/m-p/887742#M350721</link>
    <description>&lt;P&gt;Huh?&lt;/P&gt;
&lt;P&gt;You want to build a house without using wood, a hammer, nails or a saw?&lt;/P&gt;
&lt;P&gt;Why?&lt;/P&gt;</description>
    <pubDate>Thu, 03 Aug 2023 16:06:21 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-08-03T16:06:21Z</dc:date>
    <item>
      <title>Character functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-functions/m-p/887738#M350719</link>
      <description>&lt;P&gt;(Without using SCAN function and do loops, PRXCHANGE)&lt;/P&gt;&lt;P&gt;data vjk;&lt;BR /&gt;Y='Hello doc,iam (name1) i have done my laboratory test is (dbp) and the result is (110)';output;&lt;BR /&gt;Y='Hello doc,iam (name2) i have done my laboratory test is (sbp) and the result is (120)';output;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Pick bracketed words and turn characters them to uppercase, create new variables mentioned like below&lt;BR /&gt;output&lt;BR /&gt;name&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;labtest&amp;nbsp; result&lt;BR /&gt;NAME1&amp;nbsp; &amp;nbsp; WBC&amp;nbsp; &amp;nbsp; &amp;nbsp; 110&lt;BR /&gt;NAME2&amp;nbsp; &amp;nbsp;RBC&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 120&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2023 15:57:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-functions/m-p/887738#M350719</guid>
      <dc:creator>112211</dc:creator>
      <dc:date>2023-08-03T15:57:22Z</dc:date>
    </item>
    <item>
      <title>Re: Character functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-functions/m-p/887742#M350721</link>
      <description>&lt;P&gt;Huh?&lt;/P&gt;
&lt;P&gt;You want to build a house without using wood, a hammer, nails or a saw?&lt;/P&gt;
&lt;P&gt;Why?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2023 16:06:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-functions/m-p/887742#M350721</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-03T16:06:21Z</dc:date>
    </item>
    <item>
      <title>Re: Character functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-functions/m-p/887746#M350723</link>
      <description>Its possible or not ,just I want to know.</description>
      <pubDate>Thu, 03 Aug 2023 16:14:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-functions/m-p/887746#M350723</guid>
      <dc:creator>112211</dc:creator>
      <dc:date>2023-08-03T16:14:50Z</dc:date>
    </item>
    <item>
      <title>Re: Character functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-functions/m-p/887753#M350726</link>
      <description>&lt;P&gt;So let's see how many ideas we can come up with.&lt;/P&gt;
&lt;P&gt;Here is one using CHAR() and SUBSTR() on the LEFT of the assignment statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile cards truncover;
  input y $100. ;
cards4;
Hello doc,iam (name1) i have done my laboratory test is (dbp) and the result is (110)
Hello doc,iam (name2) i have done my laboratory test is (sbp) and the result is (120)
;;;;

data want;
  set have ;
  array words $30 name test value;
  loc=1;
  do word=1 to 3 while(loc&amp;lt;length(y));
    do loc=loc to length(y) while ('(' ne char(y,loc));
    end;
    if char(y,loc)='(' then do i=1 to length(y)-loc until(')'=char(y,loc+i));
      if char(y,loc+i) ne ')' then substr(words[word],i,1)=upcase(char(y,loc+i));
    end;
    loc + i;
    drop word loc i;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1691080301215.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/86411i80EFDBB4FEB06EA0/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1691080301215.png" alt="Tom_0-1691080301215.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2023 16:32:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-functions/m-p/887753#M350726</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-03T16:32:40Z</dc:date>
    </item>
    <item>
      <title>Re: Character functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-functions/m-p/887754#M350727</link>
      <description>&lt;P&gt;If all of your data looks like that with the desired values inside parentheses and in that order then SCAN is going to be a lot easier to write than PRX .&lt;/P&gt;
&lt;P&gt;You don't mention whether result is supposed to be numeric or character as a result either.&lt;/P&gt;
&lt;P&gt;No "loops" needed in this example: (assumes result should be numeric).&lt;/P&gt;
&lt;PRE&gt;data want;
   set vjk;
   length name $ 25 labtest $ 10;
   name = scan(y,2,'()');
   labtest = scan(y,4,'()');
   result = input(scan(y,6,'()'),8.);
run;&lt;/PRE&gt;
&lt;P&gt;Your PRX approach would basically be saying "get the first/second/third value inside ()". Scan does that with simpler syntax. If the ORDER of the values changes then provide a more realistic example.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2023 16:37:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-functions/m-p/887754#M350727</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-08-03T16:37:11Z</dc:date>
    </item>
    <item>
      <title>Re: Character functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-functions/m-p/887846#M350764</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*It is more like a homework task.*/
data vjk;
Y='Hello doc,iam (name1) i have done my laboratory test is (dbp) and the result is (110)';output;
Y='Hello doc,iam (name2) i have done my laboratory test is (sbp) and the result is (120)';output;
run;

data want;
set vjk;
pid=prxparse('/\((\w+)\).*\((\w+)\).*\((\w+)\)/');
if prxmatch(pid,Y) then do;
 name=upcase(prxposn(pid,1,Y));
 labtest=upcase(prxposn(pid,2,Y));
 result=upcase(prxposn(pid,3,Y));
end;
drop pid;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Aug 2023 11:49:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-functions/m-p/887846#M350764</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-08-04T11:49:06Z</dc:date>
    </item>
    <item>
      <title>Re: Character functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-functions/m-p/887874#M350780</link>
      <description>&lt;P&gt;If it's just for fun, then one way to do it without SCAN or loops or regular expressions would be use just FINDC to find the parentheses, and substrn to get the text between the parentheses.&amp;nbsp; This uses the handy start-position of FINDC.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile cards truncover;
  input y $100. ;
cards4;
Hello doc,iam (name1) i have done my laboratory test is (dbp) and the result is (110)
Hello doc,iam (name2) i have done my laboratory test is (sbp) and the result is (120)
;;;;

data want ;
  set have ;&lt;BR /&gt;
  open1=findc(y,'(') ;
  close1=findc(y,')',open1) ;

  open2=findc(y,'(',close1) ;
  close2=findc(y,')',open2) ;

  open3=findc(y,'(',close2) ;
  close3=findc(y,')',open3) ;

  Name=upcase(substrn(y,open1+1,close1-open1-1)) ;
  Test=upcase(substrn(y,open2+1,close2-open2-1)) ;
  Result=upcase(substrn(y,open3+1,close3-open3-1)) ;

  put Name= Test= Result=;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of course it's wallpaper code that screams for looping over an array...&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2023 14:06:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-functions/m-p/887874#M350780</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-08-04T14:06:32Z</dc:date>
    </item>
    <item>
      <title>Re: Character functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-functions/m-p/887906#M350799</link>
      <description>&lt;P&gt;Another option is the "_infile_ trick" (see the 2018 thread "&lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-delimit-large-dataset-28-Million-rows-into-700-variables/td-p/486750/highlight/true/page/2" target="_blank" rel="noopener"&gt;How to delimit large dataset ...&lt;/A&gt;" for a discussion)&lt;FONT face="helvetica"&gt;:&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=y);
set vjk;
infile sasautos(verify.sas) dlm='()';
if _n_=1 then input @;
_infile_=y;
input @1 y name :$upcase40. y test :$upcase20. y result @@;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Aug 2023 15:38:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-functions/m-p/887906#M350799</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-08-04T15:38:00Z</dc:date>
    </item>
    <item>
      <title>Re: Character functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-functions/m-p/887993#M350830</link>
      <description>&lt;P&gt;Bit of a silly requirement but o.k. here you go.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  Y='Hello doc,iam (name1) i have done my laboratory test is (dbp) and the result is (110)';
  output;
  Y='Hello doc,iam (name2) i have done my laboratory test is (sbp) and the result is (120)';
  output;
  Y='Hello doc,iam (name2) i have done my laboratory test is (sbp)';
  output;
run;

data want(drop=_:);
  set have;
  length name labtest result $20;
  _s1=1;
  _s2=0;

  _s1=find(y,'(',_s1)+1;
  _s2=find(y,')',_s2+1);
  if _s2 then name=upcase(substr(y,_s1,_s2-_s1));

  _s1=find(y,'(',_s1)+1;
  _s2=find(y,')',_s2+1);
  if _s2 then labtest=upcase(substr(y,_s1,_s2-_s1));

  _s1=find(y,'(',_s1)+1;
  _s2=find(y,')',_s2+1);
  if _s2 then result=upcase(substr(y,_s1,_s2-_s1));
run;

proc print data=want;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 05 Aug 2023 00:15:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-functions/m-p/887993#M350830</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-08-05T00:15:15Z</dc:date>
    </item>
  </channel>
</rss>

