<?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 Using substr in Proc SQL update in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Using-substr-in-Proc-SQL-update/m-p/772298#M31051</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I use a substr in a Proc Sql Update?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
&amp;nbsp; input x $;
datalines;
abc
bbc
ccc
run;

data test;
   set test;

   substr(x,1,1) = 't';
run;

This will give me:
tbc
tbc
tcc

I tried using the substr in a PROC SQL Update but it won't work:

proc sql; 
  update test
  set substr(x,1,1) = 't';
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;1. How do I use the substr function in a Proc SQL Update.&lt;/P&gt;&lt;P&gt;2. Is it okay to use the same dataset in a set statement, like the dataset test in the above example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Tue, 05 Oct 2021 21:28:56 GMT</pubDate>
    <dc:creator>cosmid</dc:creator>
    <dc:date>2021-10-05T21:28:56Z</dc:date>
    <item>
      <title>Using substr in Proc SQL update</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-substr-in-Proc-SQL-update/m-p/772298#M31051</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I use a substr in a Proc Sql Update?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
&amp;nbsp; input x $;
datalines;
abc
bbc
ccc
run;

data test;
   set test;

   substr(x,1,1) = 't';
run;

This will give me:
tbc
tbc
tcc

I tried using the substr in a PROC SQL Update but it won't work:

proc sql; 
  update test
  set substr(x,1,1) = 't';
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;1. How do I use the substr function in a Proc SQL Update.&lt;/P&gt;&lt;P&gt;2. Is it okay to use the same dataset in a set statement, like the dataset test in the above example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 05 Oct 2021 21:28:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-substr-in-Proc-SQL-update/m-p/772298#M31051</guid>
      <dc:creator>cosmid</dc:creator>
      <dc:date>2021-10-05T21:28:56Z</dc:date>
    </item>
    <item>
      <title>Re: Using substr in Proc SQL update</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-substr-in-Proc-SQL-update/m-p/772301#M31052</link>
      <description>&lt;P&gt;While you can use the SUBSTR() function in PROC SQL, I don't think you can you can use the version of the SUBSTR() function on the left of the equal sign.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, you most likely have to do this in a DATA step.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Oct 2021 22:04:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-substr-in-Proc-SQL-update/m-p/772301#M31052</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-05T22:04:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using substr in Proc SQL update</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-substr-in-Proc-SQL-update/m-p/772303#M31053</link>
      <description>Agreed with Paige, likely not possible to use this instance of SUBSTR (LEFT OF) in SQL. &lt;BR /&gt;You could use a combination of other functions to achieve the same output in SQL or you can use a data step. &lt;BR /&gt;&lt;BR /&gt;Something like this perhaps:&lt;BR /&gt;&lt;BR /&gt;proc sql; &lt;BR /&gt;  update test&lt;BR /&gt;  set x = catt( 't', substr(x, 2));&lt;BR /&gt;quit;</description>
      <pubDate>Tue, 05 Oct 2021 21:57:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-substr-in-Proc-SQL-update/m-p/772303#M31053</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-05T21:57:14Z</dc:date>
    </item>
    <item>
      <title>Re: Using substr in Proc SQL update</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-substr-in-Proc-SQL-update/m-p/772304#M31054</link>
      <description>Unless you're working with a DB, SAS actually recreates the dataset when using an UPDATE statement so it's not particularly more efficient than other steps AFAIK. I think if you're working on a DB there are some functions that will be more efficient but YMMV.</description>
      <pubDate>Tue, 05 Oct 2021 21:59:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-substr-in-Proc-SQL-update/m-p/772304#M31054</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-05T21:59:09Z</dc:date>
    </item>
    <item>
      <title>Re: Using substr in Proc SQL update</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-substr-in-Proc-SQL-update/m-p/772327#M31056</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/253026"&gt;@cosmid&lt;/a&gt;&amp;nbsp; Below code is fully working using a SQL Update.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input x $;
  row+1;
datalines;
abc
bbc
ccc
;

proc sql;
  delete from test
  where row=2
  ;
quit;

proc sql;
  update test
  set x=catt('t',substrn(x,2))
  where row=3
  ;
quit;

proc contents data=test;
run;quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Unless you're working with a DB, SAS actually recreates the dataset when using an UPDATE statement so it's not particularly more efficient than other steps AFAIK. I think if you're working on a DB there are some functions that will be more efficient but YMMV.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;SQL changes tables in place where possible which is why deleted observations remain physically in the table.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1633480283006.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64391iDA82A3FDF40E651D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1633480283006.png" alt="Patrick_0-1633480283006.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Oct 2021 00:35:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-substr-in-Proc-SQL-update/m-p/772327#M31056</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-10-06T00:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using substr in Proc SQL update</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-substr-in-Proc-SQL-update/m-p/772359#M31066</link>
      <description>&lt;P&gt;The use of SUBSTR on the left side of an assignment is a feature of the &lt;EM&gt;data step compiler&lt;/EM&gt; and not available anywhere else.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Oct 2021 07:09:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-substr-in-Proc-SQL-update/m-p/772359#M31066</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-06T07:09:54Z</dc:date>
    </item>
  </channel>
</rss>

