<?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: Char Function Troubles in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Char-Function-Troubles/m-p/559333#M156170</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&amp;nbsp;I wish SAS had this option. Maybe using a fourth parameter.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Maybe time for Ballot box suggestion.&lt;/P&gt;</description>
    <pubDate>Thu, 16 May 2019 14:46:08 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-05-16T14:46:08Z</dc:date>
    <item>
      <title>Char Function Troubles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-Function-Troubles/m-p/559050#M156072</link>
      <description>&lt;P&gt;Hi. In the code below I'm reading in a Proc Sql query using the DATALINES statement to a variable named USER_SQL.&amp;nbsp; I'm then trying to update the USER_SQL variable to put '/*' and '*/' around the Create Table statement.&amp;nbsp; Basically I'm trying to comment out the Create Table statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm having two problems in the second datastep below:&lt;/P&gt;
&lt;P&gt;1.&amp;nbsp; CRT_TBL_STTMNT = SUBSTR(USER_SQL, INDEX(USER_SQL,'CREATE TABLE'), INDEX(USER_SQL,' AS')+2);&lt;/P&gt;
&lt;P&gt;This statement is extracting too many characters.&amp;nbsp; I want it to pull just 'CREATE TABLE OUT.MYTAB AS', but instead it's pulling 'CREATE TABLE OUT.MYTAB AS SELECT DISTINCT'.&amp;nbsp; I can't figure out why.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2.&amp;nbsp;&amp;nbsp;USER_SQL = TRANWRD(USER_SQL, CRT_TBL_STTMNT, NEW_CRT_TBL_STTMNT);&lt;/P&gt;
&lt;P&gt;I'm trying to replace the current Create Table statement inside the USER_SQL variable with the new Create Table statement that has&amp;nbsp; the Comment signs around it, but it's failing to make the replacement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have time to take a look the code you can run is:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA USER_SQL;
  INFILE DATALINES EOF=WRITE;
  LENGTH USER_SQL $32767 ;  
  RETAIN USER_SQL;
  INPUT;
  USER_SQL=CATX(' ',USER_SQL,_INFILE_);
RETURN;
WRITE: OUTPUT;
DATALINES4;

PROC SQL;
CREATE TABLE OUT.MYTAB AS
SELECT DISTINCT 
		CLM.BENE_SK
		,1 as card
FROM	OPI_AAL.CLM AS CLM
INNER JOIN NFPP_TRD.&amp;amp;SYSUSERID._HHASWITCH_CLMS AS HHACLMS
	ON CLM.BENE_SK = HHACLMS.BENE_SK
WHERE (CLM.CLM_FROM_DT BETWEEN &amp;amp;bgn_dt AND &amp;amp;end_dt) 
	AND (CLM.CLM_PRNCPL_DGNS_CD LIKE 'I50%' or CLM.CLM_DGNS_1_CD LIKE 'I50%' or CLM.CLM_DGNS_2_CD LIKE 'I50%' 
     			or CLM.CLM_DGNS_3_CD LIKE 'I50%' or CLM.CLM_DGNS_4_CD LIKE 'I50%' or CLM.CLM_DGNS_5_CD LIKE 'I50%' 
				or CLM.CLM_DGNS_6_CD LIKE 'I50%' or CLM.CLM_DGNS_7_CD LIKE 'I50%' or CLM.CLM_DGNS_8_CD LIKE 'I50%')
	AND CLM.CLM_FINL_ACTN_IND = 'Y'
	AND CLM.CLM_TYPE_CD BETWEEN 2000 AND 2999
order by BENE_SK
;QUIT;
;;;;

DATA USER_SQL2;
SET USER_SQL;

IF FIND(USER_SQL,'CREATE TABLE') = 0 THEN CRT_TBL_IND=0; ELSE CRT_TBL_IND=1;
IF CRT_TBL_IND=1 THEN DO;
	/* PULL OUT THE CREATE TABLE STATEMENT */
	CRT_TBL_STTMNT = SUBSTR(USER_SQL, INDEX(USER_SQL,'CREATE TABLE'), INDEX(USER_SQL,' AS')+2);
	/* APPEND SAS COMMENT MARKERS AROUND THE CREATE TABLE STATEMENT */
	NEW_CRT_TBL_STTMNT = CATX(' ', '/* ',SUBSTR(USER_SQL,INDEX(USER_SQL,'CREATE TABLE'),INDEX(USER_SQL,' AS')+2),' */');
	/* REPLACE THE EXISTING CREATE TABLE STATEMENT WITH THE COMMENTED VERSION */
	USER_SQL = TRANWRD(USER_SQL, CRT_TBL_STTMNT, NEW_CRT_TBL_STTMNT);
END;
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 16:30:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-Function-Troubles/m-p/559050#M156072</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2019-05-15T16:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: Char Function Troubles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-Function-Troubles/m-p/559055#M156075</link>
      <description>&lt;P&gt;How "nice" is your SQL code?&lt;/P&gt;
&lt;P&gt;You might have better luck leaving the code broken into individual lines instead of smushing it together into a single string.&lt;/P&gt;
&lt;P&gt;Then your searches for PROC SQL and CREATE statements can be much easier (assuming that code is following some minimal formatting standards).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if left(upcase(line)) =: 'PROC SQL' and not findw(line,'noexec',,'sit') then do;
  loc=index(line,';');
  if loc then line=catx(' ',substr(line,1,loc-1),'noexec',substr(line,loc));
  else line=catx(' ',line,'noexec');
end;
if left(upcase(line))=:'CREATE TABLE' then do;
  line=cats('*',line,';');
end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 May 2019 16:31:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-Function-Troubles/m-p/559055#M156075</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-15T16:31:14Z</dc:date>
    </item>
    <item>
      <title>Re: Char Function Troubles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-Function-Troubles/m-p/559064#M156082</link>
      <description>&lt;P&gt;Unfortunately it's going to be code from today to code from 10 years ago - and from hundreds of different users to boot.&lt;BR /&gt;&lt;BR /&gt;Do you see any reason why this statement is pulling too many characters? It seems straight forward enough.&amp;nbsp; I don't get it.&lt;BR /&gt;&lt;BR /&gt;CRT_TBL_STTMNT = SUBSTR(USER_SQL, INDEX(USER_SQL,'CREATE TABLE'), INDEX(USER_SQL,' AS')+2);&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 16:55:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-Function-Troubles/m-p/559064#M156082</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2019-05-15T16:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: Char Function Troubles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-Function-Troubles/m-p/559077#M156087</link>
      <description>&lt;P&gt;SUBSTR (target, startcharacter, NUMBEROFCHARACTERS) not position&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DATA USER_SQL2;
SET USER_SQL;

IF FIND(USER_SQL,'CREATE TABLE') = 0 THEN CRT_TBL_IND=0; ELSE CRT_TBL_IND=1;
IF CRT_TBL_IND=1 THEN DO;
	/* PULL OUT THE CREATE TABLE STATEMENT */
   createpos = INDEX(USER_SQL,'CREATE TABLE');
   ASpos =INDEX(USER_SQL,' AS');
	CRT_TBL_STTMNT = SUBSTR(USER_SQL,createpos,(aspos-createpos) +3);
END;
RUN;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 May 2019 17:27:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-Function-Troubles/m-p/559077#M156087</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-15T17:27:04Z</dc:date>
    </item>
    <item>
      <title>Re: Char Function Troubles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-Function-Troubles/m-p/559123#M156096</link>
      <description>Ugh!  Stupid, stupid, stupid.  Thank you so much.</description>
      <pubDate>Wed, 15 May 2019 19:29:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-Function-Troubles/m-p/559123#M156096</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2019-05-15T19:29:59Z</dc:date>
    </item>
    <item>
      <title>Re: Char Function Troubles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-Function-Troubles/m-p/559146#M156105</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/79805"&gt;@buechler66&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Ugh! Stupid, stupid, stupid. Thank you so much.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I know at least one programming language where there are two forms of substr&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;substr(string,start position , end position)&lt;/P&gt;
&lt;P&gt;substr(string,start position ; length)&lt;/P&gt;
&lt;P&gt;the delimiter between the start and end/length tells the function which one to do. WARNING: I may have the examples backwards as far as end position&amp;nbsp;vs length but I think the point is valid.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if you think that approach may have lead to some code frustration you are absolutely right.&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 20:05:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-Function-Troubles/m-p/559146#M156105</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-15T20:05:07Z</dc:date>
    </item>
    <item>
      <title>Re: Char Function Troubles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-Function-Troubles/m-p/559203#M156126</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&amp;nbsp;I wish SAS had this option. Maybe using a fourth parameter.&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2019 02:51:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-Function-Troubles/m-p/559203#M156126</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-05-16T02:51:03Z</dc:date>
    </item>
    <item>
      <title>Re: Char Function Troubles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-Function-Troubles/m-p/559333#M156170</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&amp;nbsp;I wish SAS had this option. Maybe using a fourth parameter.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Maybe time for Ballot box suggestion.&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2019 14:46:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-Function-Troubles/m-p/559333#M156170</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-16T14:46:08Z</dc:date>
    </item>
    <item>
      <title>Re: Char Function Troubles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Char-Function-Troubles/m-p/559522#M156244</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt; Maybe time for Ballot box suggestion.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;I have proposed countless ideas there! &lt;A href="https://communities.sas.com/t5/forums/searchpage/tab/message?filter=location%2CauthorId&amp;amp;q=a&amp;amp;location=idea-board%3Asas_ideas&amp;amp;author_id=16961" target="_self"&gt;Dozens I think&lt;/A&gt;. And not only there,&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Visual-Analytics/Large-list-of-suggested-improvements-for-VA-7-2/m-p/268184" target="_self"&gt;here&lt;/A&gt;&amp;nbsp;and&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Enterprise-Guide/Small-list-of-suggested-improvements-for-EG/m-p/293023" target="_self"&gt;here&lt;/A&gt;&amp;nbsp;too.&lt;/P&gt;
&lt;P&gt;They seem to be gathering dust rather nicely.&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2019 00:15:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Char-Function-Troubles/m-p/559522#M156244</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-05-17T00:15:55Z</dc:date>
    </item>
  </channel>
</rss>

