<?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: adding parentheses to observations in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/adding-parentheses-to-observations/m-p/43681#M11442</link>
    <description>The variable is composed as &lt;BR /&gt;
ONE_LONG_STRING.  To be more specific, this variable is a concatenation of three variables V1,V2,V3).  V1-V3 are currently retained in my current data set though.  &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
The pattern of the variable can fluctuate.</description>
    <pubDate>Wed, 20 Jan 2010 20:58:34 GMT</pubDate>
    <dc:creator>Hart</dc:creator>
    <dc:date>2010-01-20T20:58:34Z</dc:date>
    <item>
      <title>adding parentheses to observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/adding-parentheses-to-observations/m-p/43679#M11440</link>
      <description>I would like to add parentheses to observations to certain portions of my observation. If a observation contains a characters I would like to enclose that and subsequent characters/numbers with parentheses.   For example I have observations:&lt;BR /&gt;
&lt;BR /&gt;
16 U.S.C. 3372a1				&lt;BR /&gt;
16 U.S.C. 668a&lt;BR /&gt;
17 U.S.C. 506a1c&lt;BR /&gt;
18 U.S.C. 1029c1ai&lt;BR /&gt;
21 U.S.C. 353e2a&lt;BR /&gt;
26 U.S.C. 5845&lt;BR /&gt;
28 U.S.C. 2461c&lt;BR /&gt;
&lt;BR /&gt;
I would like the outcome to appear as&lt;BR /&gt;
&lt;BR /&gt;
16 U.S.C. 3372(a)(1)				&lt;BR /&gt;
16 U.S.C. 668(a)&lt;BR /&gt;
17 U.S.C. 506(a)(1)(c)&lt;BR /&gt;
18 U.S.C. 1029(c)(1)(a)(i)&lt;BR /&gt;
21 U.S.C. 353(e)(2)(a)&lt;BR /&gt;
26 U.S.C. 5845&lt;BR /&gt;
28 U.S.C. 2461(c)		&lt;BR /&gt;
&lt;BR /&gt;
Is there any way to do this in SAS or even SQL ?</description>
      <pubDate>Wed, 20 Jan 2010 20:21:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/adding-parentheses-to-observations/m-p/43679#M11440</guid>
      <dc:creator>Hart</dc:creator>
      <dc:date>2010-01-20T20:21:10Z</dc:date>
    </item>
    <item>
      <title>Re: adding parentheses to observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/adding-parentheses-to-observations/m-p/43680#M11441</link>
      <description>Hi:&lt;BR /&gt;
  A bit more information is needed. For example, is your observation composed of only 1 variable which is one long text string let's say the variable is called ONE_LONG_STRING&lt;BR /&gt;
[pre]&lt;BR /&gt;
ONE_LONG_STRING&lt;BR /&gt;
16 U.S.C. 3372a1 &lt;BR /&gt;
16 U.S.C. 668a&lt;BR /&gt;
17 U.S.C. 506a1c&lt;BR /&gt;
18 U.S.C. 1029c1ai&lt;BR /&gt;
21 U.S.C. 353e2a&lt;BR /&gt;
26 U.S.C. 5845&lt;BR /&gt;
28 U.S.C. 2461c&lt;BR /&gt;
[/pre]&lt;BR /&gt;
   &lt;BR /&gt;
OR, is your observation composed of 3 variables, perhaps V1, V2 and V3??&lt;BR /&gt;
[pre]&lt;BR /&gt;
V1   V2    V3&lt;BR /&gt;
16 U.S.C. 3372a1 &lt;BR /&gt;
16 U.S.C. 668a&lt;BR /&gt;
17 U.S.C. 506a1c&lt;BR /&gt;
18 U.S.C. 1029c1ai&lt;BR /&gt;
21 U.S.C. 353e2a&lt;BR /&gt;
26 U.S.C. 5845&lt;BR /&gt;
28 U.S.C. 2461c&lt;BR /&gt;
[/pre]&lt;BR /&gt;
   &lt;BR /&gt;
If the variable is one long text string, does it always follow this pattern:&lt;BR /&gt;
xx X.X.X xxx &lt;BR /&gt;
...or...&lt;BR /&gt;
xx X.X.X xxxx&lt;BR /&gt;
 &lt;BR /&gt;
What you want to do is possible either with SCAN and SUBSTR functions or possible with PRX functions. But first, knowing whether you have 1 variable for every observation or 3 variables for every observation is very helpful.&lt;BR /&gt;
 &lt;BR /&gt;
An observation in SAS is sometimes called a ROW or a RECORD in other languages or data bases. Each SAS observation is composed of variables, which are also called COLUMNS or FIELDS in other languages or data bases.&lt;BR /&gt;
 &lt;BR /&gt;
So while you might have an observation or row with only 1 variable or column, it is unlikely. Knowing the structure of the observations and the variable names would be helpful.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Wed, 20 Jan 2010 20:40:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/adding-parentheses-to-observations/m-p/43680#M11441</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-01-20T20:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: adding parentheses to observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/adding-parentheses-to-observations/m-p/43681#M11442</link>
      <description>The variable is composed as &lt;BR /&gt;
ONE_LONG_STRING.  To be more specific, this variable is a concatenation of three variables V1,V2,V3).  V1-V3 are currently retained in my current data set though.  &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
The pattern of the variable can fluctuate.</description>
      <pubDate>Wed, 20 Jan 2010 20:58:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/adding-parentheses-to-observations/m-p/43681#M11442</guid>
      <dc:creator>Hart</dc:creator>
      <dc:date>2010-01-20T20:58:34Z</dc:date>
    </item>
    <item>
      <title>Re: adding parentheses to observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/adding-parentheses-to-observations/m-p/43682#M11443</link>
      <description>Hi:&lt;BR /&gt;
  It might be easier to put the parentheses into V3 before ONE_LONG_STRING is created. When you say that the pattern of the variable can fluctuate, it would be crucial to know HOW the value can fluctuate...for example, if we were looking at only V3, would V3 -always- be either 3 or 4 numbers which could be followed by:&lt;BR /&gt;
-- nothing else (V1=26 V2=U.S.C. V3=5845 )&lt;BR /&gt;
-- any combination of numbers and letters (V1=18 V2=U.S.C. V3=1029c1ai)&lt;BR /&gt;
-- just a single letter(V1=16 V2=U.S.C. V3=668a)&lt;BR /&gt;
???&lt;BR /&gt;
  &lt;BR /&gt;
How else would it be possible for V3 to fluctuate? Or, if you want to deal with ONE_LONG_STRING, how would it be possible for ONE_LONG_STRING to fluctuate???? Whether you're doing a SCAN/SUBSTR approach or a PRX approach, all the possible patterns must be known. For example, are these fluctuations possible?&lt;BR /&gt;
[pre]&lt;BR /&gt;
V1   V2           V3&lt;BR /&gt;
16   U.S.C.      3372a1 &lt;BR /&gt;
16x  U.S.C.10    888a1b2c3&lt;BR /&gt;
1694 U.S.C.      668a&lt;BR /&gt;
a17  U.S.C.999   506a1c&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
The rules for parsing or finding the pattern must be known before you can code a solution.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Wed, 20 Jan 2010 21:31:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/adding-parentheses-to-observations/m-p/43682#M11443</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-01-20T21:31:47Z</dc:date>
    </item>
    <item>
      <title>Re: adding parentheses to observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/adding-parentheses-to-observations/m-p/43683#M11444</link>
      <description>I agree that adding parentheses into V3 will likely be the best option.  This is the only variable that will need the additon of the parentheses.&lt;BR /&gt;
&lt;BR /&gt;
V3 is created from US statutes and can be any of the combinations (V3=5845, V3=1029c1ai, V3=668a, V3=1).  As of now I have over 1k unique statutes, rows.   V3 will not always be either 3 or 4 numbers.  V3 may have as few as 1and max of 7 numbers.</description>
      <pubDate>Thu, 21 Jan 2010 13:57:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/adding-parentheses-to-observations/m-p/43683#M11444</guid>
      <dc:creator>Hart</dc:creator>
      <dc:date>2010-01-21T13:57:59Z</dc:date>
    </item>
    <item>
      <title>Re: adding parentheses to observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/adding-parentheses-to-observations/m-p/43684#M11445</link>
      <description>data two;&lt;BR /&gt;
set one;&lt;BR /&gt;
length newstr $40;&lt;BR /&gt;
if anyalpha(v3) then do;&lt;BR /&gt;
newstr = substr(v3, 1, anyalpha(v3)-1);&lt;BR /&gt;
do i = anyalpha(v3) to length(v3);&lt;BR /&gt;
  newstr = cats(newstr, '(', substr(v3, i, 1), ')');&lt;BR /&gt;
end;&lt;BR /&gt;
end;&lt;BR /&gt;
else newstr = v3;&lt;BR /&gt;
run;</description>
      <pubDate>Thu, 21 Jan 2010 14:35:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/adding-parentheses-to-observations/m-p/43684#M11445</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2010-01-21T14:35:12Z</dc:date>
    </item>
    <item>
      <title>Re: adding parentheses to observations</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/adding-parentheses-to-observations/m-p/43685#M11446</link>
      <description>ahh yes!  exactly.  Thanks!&lt;BR /&gt;
&lt;BR /&gt;
Have never used the anyalpha(v3)...type of statement before but love learning new code.  so many thanks again.</description>
      <pubDate>Thu, 21 Jan 2010 15:11:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/adding-parentheses-to-observations/m-p/43685#M11446</guid>
      <dc:creator>Hart</dc:creator>
      <dc:date>2010-01-21T15:11:23Z</dc:date>
    </item>
  </channel>
</rss>

