<?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: extracting a single character inside a SQL proc? is substring the way? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/extracting-a-single-character-inside-a-SQL-proc-is-substring-the/m-p/752265#M29751</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/322866"&gt;@cieffegi&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for sharing the code and error message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks to me like there might be something missing before the &lt;FONT face="courier new,courier"&gt;substring()&lt;/FONT&gt; function is used.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please share the log showing the &lt;U&gt;whole&lt;/U&gt; &lt;FONT face="courier new,courier"&gt;proc sql&lt;/FONT&gt; step, using the "&amp;lt;/&amp;gt;" to post the details, so that we can see the whole context.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
    <pubDate>Tue, 06 Jul 2021 11:41:45 GMT</pubDate>
    <dc:creator>Amir</dc:creator>
    <dc:date>2021-07-06T11:41:45Z</dc:date>
    <item>
      <title>extracting a single character inside a SQL proc? is substring the way?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/extracting-a-single-character-inside-a-SQL-proc-is-substring-the/m-p/752260#M29750</link>
      <description>&lt;P&gt;I have this sql proc:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table last_positions as select distinct&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;a.*,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;b.RATING AS numerical_rating&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;from last_positions_temp as a&lt;BR /&gt;left join &amp;amp;LIB_INP..closed_positions as b&lt;BR /&gt;on a.NDG = b.NDG and a.extr_dt = b.extr_dt&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;Now, this is the problem:&lt;BR /&gt;the "RATING" table contains two digit value like "R1", "R2", "R3" up to "R9".&lt;BR /&gt;I want to keep only the numerical part.&lt;BR /&gt;I have tried several sintax like&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;substring(b.RATING,2,1) AS numerical_rating&lt;BR /&gt;or&lt;BR /&gt;substr (b.RATING,2,1) AS numerical_rating&lt;BR /&gt;or&amp;nbsp;b.RATING AS numerical_rating = substring(b.RATING,2,1) AS numerical_rating&lt;BR /&gt;and also other combinations.&lt;BR /&gt;&lt;BR /&gt;Every time i get this error message:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;551 SUBSTRING(b.RATING,2,1) AS stato_dr&lt;BR /&gt;-&lt;BR /&gt;22&lt;BR /&gt;76&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, -, /, &amp;lt;, &amp;lt;=,&lt;BR /&gt;&amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, BETWEEN, CONTAINS, EQ, EQT, FROM, GE, GET, GT, GTT, IN,&lt;BR /&gt;IS, LE, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, ^, ^=, |, ||, ~, ~=.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;BR /&gt;NOTE: Remote submit to SERV complete.&lt;BR /&gt;NOTE: Remote submit to SERV commencing.&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 47.34 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;is it possible to acheive the desired result inside the proc sql or should i use a run around of some sort?&lt;BR /&gt;Thank you&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jul 2021 11:06:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/extracting-a-single-character-inside-a-SQL-proc-is-substring-the/m-p/752260#M29750</guid>
      <dc:creator>cieffegi</dc:creator>
      <dc:date>2021-07-06T11:06:38Z</dc:date>
    </item>
    <item>
      <title>Re: extracting a single character inside a SQL proc? is substring the way?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/extracting-a-single-character-inside-a-SQL-proc-is-substring-the/m-p/752265#M29751</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/322866"&gt;@cieffegi&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for sharing the code and error message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks to me like there might be something missing before the &lt;FONT face="courier new,courier"&gt;substring()&lt;/FONT&gt; function is used.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please share the log showing the &lt;U&gt;whole&lt;/U&gt; &lt;FONT face="courier new,courier"&gt;proc sql&lt;/FONT&gt; step, using the "&amp;lt;/&amp;gt;" to post the details, so that we can see the whole context.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jul 2021 11:41:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/extracting-a-single-character-inside-a-SQL-proc-is-substring-the/m-p/752265#M29751</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2021-07-06T11:41:45Z</dc:date>
    </item>
    <item>
      <title>Re: extracting a single character inside a SQL proc? is substring the way?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/extracting-a-single-character-inside-a-SQL-proc-is-substring-the/m-p/752289#M29755</link>
      <description>&lt;P&gt;this is the entire program i'm trying to use:&lt;/P&gt;&lt;PRE&gt;filename pgm_auto '/crediti/MOTORI/01_COMUNE/autoexec/auto_batch_noabend.sas';
%inc pgm_auto;
/*%write_log (name=imamac_xx_datamart_proposte, motore = 01_COMUNE);*/

data _null_;
 TEMPO = put(time(),time8.);
 call symput ('TEMPO',TEMPO);
run;

%put /===================================================================/;
%put |   PGM: engine_XX_DATAMART_PROPOSTE   - START : &amp;amp;TEMPO.               |;
%put /===================================================================/;


/*Definizione parametri librerie e date*/

%LET LIB_INP=PALL_INP;
%LET LIB_DMT=PALL_DTM;

/*intercetto l'ultima proposta per ogni cdg*/
proc summary data = &amp;amp;LIB_INP..closed_positions missing nway;
class NDG; 
var EXTR_DT;
output out = last_positions_temp max=;
run;


proc sql;
 create table last_positions as select distinct 
  a.*,
  substring(b.RATING,2,1)  AS numerical_rating
   
  from last_positions_temp as a
left join &amp;amp;LIB_INP..closed_positions as b
on a.NDG = b.NDG and a.EXTR_DT = b.EXTR_DT
quit;&lt;/PRE&gt;&lt;P&gt;and this is the log i get from it&lt;/P&gt;&lt;PRE&gt;NOTE: Ambiente inizializzato correttamente

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds


/===================================================================/
|   PGM: engine_XX_DATAMART_PROPOSTE   - START : 14:46:18               |
/===================================================================/

NOTE: There were 632085 observations read from the data set PALL_INP.closed_positions.
NOTE: The data set WORK.last_positions_temp has 221755 observations and 5 variables.
NOTE: Compressing data set WORK.last_positions_temp increased size by 27.94 percent.
      Compressed is 174 pages; un-compressed would require 136 pages.
NOTE: PROCEDURE SUMMARY used (Total process time):
      real time           1.26 seconds
      cpu time            2.41 seconds


334     substring(b.RATING,2,1)  AS numerical_rating
                                             -
                                             22
                                             76
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, -, /, &amp;lt;, &amp;lt;=,
              &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, BETWEEN, CONTAINS, EQ, EQT, FROM, GE, GET, GT, GTT, IN,
              IS, LE, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, ^, ^=, |, ||, ~, ~=.

ERROR 76-322: Syntax error, statement will be ignored.

NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
NOTE: Remote submit to SERV complete.&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Jul 2021 13:01:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/extracting-a-single-character-inside-a-SQL-proc-is-substring-the/m-p/752289#M29755</guid>
      <dc:creator>cieffegi</dc:creator>
      <dc:date>2021-07-06T13:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: extracting a single character inside a SQL proc? is substring the way?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/extracting-a-single-character-inside-a-SQL-proc-is-substring-the/m-p/752310#M29759</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/322866"&gt;@cieffegi&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the info.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have you tried &lt;FONT face="courier new,courier"&gt;substr&lt;/FONT&gt; in stead of substring, as per the documentation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/v_006/lefunctionsref/p0uev77ebdwy90n1rsd7hwjd2qc3.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/v_006/lefunctionsref/p0uev77ebdwy90n1rsd7hwjd2qc3.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jul 2021 13:33:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/extracting-a-single-character-inside-a-SQL-proc-is-substring-the/m-p/752310#M29759</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2021-07-06T13:33:22Z</dc:date>
    </item>
    <item>
      <title>Re: extracting a single character inside a SQL proc? is substring the way?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/extracting-a-single-character-inside-a-SQL-proc-is-substring-the/m-p/752314#M29760</link>
      <description>it is the first thing i have tried.&lt;BR /&gt;Unfortunately, it doesn't work.</description>
      <pubDate>Tue, 06 Jul 2021 13:55:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/extracting-a-single-character-inside-a-SQL-proc-is-substring-the/m-p/752314#M29760</guid>
      <dc:creator>cieffegi</dc:creator>
      <dc:date>2021-07-06T13:55:06Z</dc:date>
    </item>
    <item>
      <title>Re: extracting a single character inside a SQL proc? is substring the way?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/extracting-a-single-character-inside-a-SQL-proc-is-substring-the/m-p/752326#M29762</link>
      <description>&lt;P&gt;There appears to be a semi colon missing (";") before the &lt;FONT face="courier new,courier"&gt;quit&lt;/FONT&gt; for the &lt;FONT face="courier new,courier"&gt;proc sql.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't think it would cause the problem, but it should be there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please try adding it and see what happens.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jul 2021 14:37:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/extracting-a-single-character-inside-a-SQL-proc-is-substring-the/m-p/752326#M29762</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2021-07-06T14:37:20Z</dc:date>
    </item>
    <item>
      <title>Re: extracting a single character inside a SQL proc? is substring the way?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/extracting-a-single-character-inside-a-SQL-proc-is-substring-the/m-p/752330#M29764</link>
      <description>&lt;P&gt;you won't beleive, that was all the issue!&lt;BR /&gt;Now it works,&lt;/P&gt;&lt;P&gt;thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jul 2021 14:53:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/extracting-a-single-character-inside-a-SQL-proc-is-substring-the/m-p/752330#M29764</guid>
      <dc:creator>cieffegi</dc:creator>
      <dc:date>2021-07-06T14:53:31Z</dc:date>
    </item>
    <item>
      <title>Re: extracting a single character inside a SQL proc? is substring the way?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/extracting-a-single-character-inside-a-SQL-proc-is-substring-the/m-p/752331#M29765</link>
      <description>&lt;P&gt;Looks like there is some invisible character near the underscore in the name you are trying to give the new variable.&lt;/P&gt;
&lt;P&gt;Try re-typing that line of the program.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jul 2021 14:53:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/extracting-a-single-character-inside-a-SQL-proc-is-substring-the/m-p/752331#M29765</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-06T14:53:33Z</dc:date>
    </item>
    <item>
      <title>Re: extracting a single character inside a SQL proc? is substring the way?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/extracting-a-single-character-inside-a-SQL-proc-is-substring-the/m-p/752338#M29767</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/322866"&gt;@cieffegi&lt;/a&gt;, glad to hear it is working and thanks for marking a post as the solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was going to suggest using &lt;FONT face="courier new,courier"&gt;validate&lt;/FONT&gt; which "Checks the accuracy of a query expression's syntax and semantics without executing the expression" to see if that gave any clues, and when I tried it after substituting sashelp table names in place of yours:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
/*  create table last_positions as  */
 	validate
 	select distinct 
 	a.*,
 	substr(b.name,2,1)  AS numerical_rating
   
 	from sashelp.cars as a
	left join sashelp.class as b
	on a.make = b.name and a.cylinders = b.age
	;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;no issues were reported:&lt;/P&gt;
&lt;PRE&gt;73         proc sql;
 74         /*  create table last_positions as  */
 75          validate
 76          select distinct
 77          a.*,
 78          substr(b.name,2,1)  AS numerical_rating
 79         
 80          from sashelp.cars as a
 81         left join sashelp.class as b
 82         on a.make = b.name and a.cylinders = b.age
 83         ;
 NOTE: PROC SQL statement has valid syntax.
 84         quit;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you might find using it useful in future.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jul 2021 15:20:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/extracting-a-single-character-inside-a-SQL-proc-is-substring-the/m-p/752338#M29767</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2021-07-06T15:20:10Z</dc:date>
    </item>
  </channel>
</rss>

