<?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: How do I parse through a string? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-parse-through-a-string/m-p/738925#M230558</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/370997"&gt;@FrustratedBio&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am attempting to run the code below in an attempt to recreate variables n1-n5 from the array. The problem is, it is not currenlty working and I can't figure out why.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data STRING;&lt;BR /&gt;Input STRING $10.&lt;BR /&gt;X 1-2&lt;BR /&gt;Y 3&lt;BR /&gt;N1 6&lt;BR /&gt;N2 7&lt;BR /&gt;N3 8&lt;BR /&gt;N4 9&lt;BR /&gt;N5 10;&lt;BR /&gt;State= Upcase (substr(STRING, 4,2));&lt;BR /&gt;Array N[5] $5 N1-N5;&lt;BR /&gt;DO I= 1 to 5;&lt;BR /&gt;N [I]= scan(String, I,.);&lt;BR /&gt;end;&lt;BR /&gt;Drop I;&lt;BR /&gt;Datalines;&lt;BR /&gt;123nj76543&lt;BR /&gt;892NY10203&lt;BR /&gt;876pA83745&lt;BR /&gt;;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;One of the main problems you are having is that your read values into variables N1 through N5 as numeric values and then try to force use as character values, the $5 in the Array and Scan function.&lt;/P&gt;
&lt;P&gt;Once a variable is created, and the input statement is implicitly creating everything except String as numeric, the type cannot change.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is this what you expected:&lt;/P&gt;
&lt;PRE&gt;Data STRING;
Input STRING $10.
X 1-2
Y 3
N1 6
N2 7
N3 8
N4 9
N5 10;
State= Upcase (substr(STRING, 4,2));
Datalines;
123nj76543
892NY10203
876pA83745
;&lt;/PRE&gt;
&lt;P&gt;or maybe&lt;/P&gt;
&lt;PRE&gt;Data STRING;
Input STRING $10.
X 1-2
Y 3
N1 $ 6 
N2 $ 7
N3 $ 8
N4 $ 9
N5 $ 10;
State= Upcase (substr(STRING, 4,2));
Datalines;
123nj76543
892NY10203
876pA83745
;&lt;/PRE&gt;
&lt;P&gt;or maybe&lt;/P&gt;
&lt;PRE&gt;Data STRING;
Input STRING $10.
X 1-2
Y 3
N1 6
N2 7
N3 8
N4 9
N5 10;
State= Upcase (substr(STRING, 4,2));
Array Z[5] $5 Z1-Z5;
DO I= 1 to 5;
Z[I]= substr(String,i+5,1);
end;
Drop I;
Datalines;
123nj76543
892NY10203
876pA83745
;&lt;/PRE&gt;
&lt;P&gt;Read you logs. Your first code shows these messages&lt;/P&gt;
&lt;PRE&gt;258  Data STRING;
259  Input STRING $10.
260  X 1-2
261  Y 3
262  N1 6
263  N2 7
264  N3 8
265  N4 9
266  N5 10;
267  State= Upcase (substr(STRING, 4,2));
268  Array N[5] $5 N1-N5;
269  DO I= 1 to 5;
270  N [I]= scan(String, I,.);
271  end;
272  Drop I;
273  Datalines;

NOTE: Numeric values have been converted to character values at the places given by:
      (Line):(Column).
      270:23
NOTE: Character values have been converted to numeric values at the places given by:
      (Line):(Column).
      270:1
NOTE: Invalid numeric data, '123nj76543' , at line 270 column 8.
RULE:      ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+--
274        123nj76543
STRING=123nj76543 X=12 Y=3 N1=. N2=. N3=. N4=. N5=. State=NJ I=6 _ERROR_=1 _N_=1
NOTE: Invalid numeric data, '892NY10203' , at line 270 column 8.
275        892NY10203
STRING=892NY10203 X=89 Y=2 N1=. N2=. N3=. N4=. N5=. State=NY I=6 _ERROR_=1 _N_=2
NOTE: Invalid numeric data, '876pA83745' , at line 270 column 8.
276        876pA83745
STRING=876pA83745 X=87 Y=6 N1=. N2=. N3=. N4=. N5=. State=PA I=6 _ERROR_=1 _N_=3
NOTE: The data set WORK.STRING has 3 observations and 9 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds

&lt;/PRE&gt;
&lt;P&gt;The invalid data on line 270 is from the SCAN function. The dot in your scan is not a valid SCAN function third parameter. It has to hold a character value either as a variable or a quoted string such as ".". But there is no obvious delimiter or separator in the value of String so you need a different approach to get values out of it with character functions.&lt;/P&gt;</description>
    <pubDate>Tue, 04 May 2021 14:57:52 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-05-04T14:57:52Z</dc:date>
    <item>
      <title>How do I parse through a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-parse-through-a-string/m-p/738784#M230500</link>
      <description>&lt;P&gt;I am attempting to run the code below in an attempt to recreate variables n1-n5 from the array. The problem is, it is not currenlty working and I can't figure out why.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data STRING;&lt;BR /&gt;Input STRING $10.&lt;BR /&gt;X 1-2&lt;BR /&gt;Y 3&lt;BR /&gt;N1 6&lt;BR /&gt;N2 7&lt;BR /&gt;N3 8&lt;BR /&gt;N4 9&lt;BR /&gt;N5 10;&lt;BR /&gt;State= Upcase (substr(STRING, 4,2));&lt;BR /&gt;Array N[5] $5 N1-N5;&lt;BR /&gt;DO I= 1 to 5;&lt;BR /&gt;N [I]= scan(String, I,.);&lt;BR /&gt;end;&lt;BR /&gt;Drop I;&lt;BR /&gt;Datalines;&lt;BR /&gt;123nj76543&lt;BR /&gt;892NY10203&lt;BR /&gt;876pA83745&lt;BR /&gt;;&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 05:12:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-parse-through-a-string/m-p/738784#M230500</guid>
      <dc:creator>FrustratedBio</dc:creator>
      <dc:date>2021-05-04T05:12:05Z</dc:date>
    </item>
    <item>
      <title>Re: How do I parse through a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-parse-through-a-string/m-p/738785#M230501</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/370997"&gt;@FrustratedBio&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am attempting to run the code below in an attempt to recreate variables n1-n5 from the array. The problem is, &lt;FONT color="#FF6600"&gt;&lt;STRONG&gt;it is not currenlty working &lt;/STRONG&gt;&lt;/FONT&gt;and I can't figure out why. &lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What does the highlighted part mean? Do you get any errors or is the result not meeting your expectations? So please explain what you expect. If there are any unexpected notes in the log, post it using the "insert code"-button.&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 05:18:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-parse-through-a-string/m-p/738785#M230501</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-05-04T05:18:25Z</dc:date>
    </item>
    <item>
      <title>Re: How do I parse through a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-parse-through-a-string/m-p/738888#M230543</link>
      <description>Hello again and thank you for your reply. I am trying to use the scan function in an array to generate values N1-N5---same as the ones in the input statement, only the question requires an array. I just put them in the input for reference. There is no error message, but the array is not outputting any values from the string.</description>
      <pubDate>Tue, 04 May 2021 12:56:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-parse-through-a-string/m-p/738888#M230543</guid>
      <dc:creator>FrustratedBio</dc:creator>
      <dc:date>2021-05-04T12:56:33Z</dc:date>
    </item>
    <item>
      <title>Re: How do I parse through a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-parse-through-a-string/m-p/738895#M230547</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/370997"&gt;@FrustratedBio&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hello again and thank you for your reply. I am trying to use the scan function in an array to generate values N1-N5---same as the ones in the input statement, only the question requires an array. I just put them in the input for reference. There is no error message, but the array is not outputting any values from the string.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What is the delimiter that you want to use for the SCAN() function?&amp;nbsp; I do not see any delimiter in your source text (datalines/cards).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you don't have a delimiter than SCAN() is not the function to use.&lt;/P&gt;
&lt;P&gt;If you just want a single character try the CHAR() function.&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 13:20:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-parse-through-a-string/m-p/738895#M230547</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-04T13:20:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do I parse through a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-parse-through-a-string/m-p/738925#M230558</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/370997"&gt;@FrustratedBio&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am attempting to run the code below in an attempt to recreate variables n1-n5 from the array. The problem is, it is not currenlty working and I can't figure out why.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data STRING;&lt;BR /&gt;Input STRING $10.&lt;BR /&gt;X 1-2&lt;BR /&gt;Y 3&lt;BR /&gt;N1 6&lt;BR /&gt;N2 7&lt;BR /&gt;N3 8&lt;BR /&gt;N4 9&lt;BR /&gt;N5 10;&lt;BR /&gt;State= Upcase (substr(STRING, 4,2));&lt;BR /&gt;Array N[5] $5 N1-N5;&lt;BR /&gt;DO I= 1 to 5;&lt;BR /&gt;N [I]= scan(String, I,.);&lt;BR /&gt;end;&lt;BR /&gt;Drop I;&lt;BR /&gt;Datalines;&lt;BR /&gt;123nj76543&lt;BR /&gt;892NY10203&lt;BR /&gt;876pA83745&lt;BR /&gt;;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;One of the main problems you are having is that your read values into variables N1 through N5 as numeric values and then try to force use as character values, the $5 in the Array and Scan function.&lt;/P&gt;
&lt;P&gt;Once a variable is created, and the input statement is implicitly creating everything except String as numeric, the type cannot change.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is this what you expected:&lt;/P&gt;
&lt;PRE&gt;Data STRING;
Input STRING $10.
X 1-2
Y 3
N1 6
N2 7
N3 8
N4 9
N5 10;
State= Upcase (substr(STRING, 4,2));
Datalines;
123nj76543
892NY10203
876pA83745
;&lt;/PRE&gt;
&lt;P&gt;or maybe&lt;/P&gt;
&lt;PRE&gt;Data STRING;
Input STRING $10.
X 1-2
Y 3
N1 $ 6 
N2 $ 7
N3 $ 8
N4 $ 9
N5 $ 10;
State= Upcase (substr(STRING, 4,2));
Datalines;
123nj76543
892NY10203
876pA83745
;&lt;/PRE&gt;
&lt;P&gt;or maybe&lt;/P&gt;
&lt;PRE&gt;Data STRING;
Input STRING $10.
X 1-2
Y 3
N1 6
N2 7
N3 8
N4 9
N5 10;
State= Upcase (substr(STRING, 4,2));
Array Z[5] $5 Z1-Z5;
DO I= 1 to 5;
Z[I]= substr(String,i+5,1);
end;
Drop I;
Datalines;
123nj76543
892NY10203
876pA83745
;&lt;/PRE&gt;
&lt;P&gt;Read you logs. Your first code shows these messages&lt;/P&gt;
&lt;PRE&gt;258  Data STRING;
259  Input STRING $10.
260  X 1-2
261  Y 3
262  N1 6
263  N2 7
264  N3 8
265  N4 9
266  N5 10;
267  State= Upcase (substr(STRING, 4,2));
268  Array N[5] $5 N1-N5;
269  DO I= 1 to 5;
270  N [I]= scan(String, I,.);
271  end;
272  Drop I;
273  Datalines;

NOTE: Numeric values have been converted to character values at the places given by:
      (Line):(Column).
      270:23
NOTE: Character values have been converted to numeric values at the places given by:
      (Line):(Column).
      270:1
NOTE: Invalid numeric data, '123nj76543' , at line 270 column 8.
RULE:      ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+--
274        123nj76543
STRING=123nj76543 X=12 Y=3 N1=. N2=. N3=. N4=. N5=. State=NJ I=6 _ERROR_=1 _N_=1
NOTE: Invalid numeric data, '892NY10203' , at line 270 column 8.
275        892NY10203
STRING=892NY10203 X=89 Y=2 N1=. N2=. N3=. N4=. N5=. State=NY I=6 _ERROR_=1 _N_=2
NOTE: Invalid numeric data, '876pA83745' , at line 270 column 8.
276        876pA83745
STRING=876pA83745 X=87 Y=6 N1=. N2=. N3=. N4=. N5=. State=PA I=6 _ERROR_=1 _N_=3
NOTE: The data set WORK.STRING has 3 observations and 9 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds

&lt;/PRE&gt;
&lt;P&gt;The invalid data on line 270 is from the SCAN function. The dot in your scan is not a valid SCAN function third parameter. It has to hold a character value either as a variable or a quoted string such as ".". But there is no obvious delimiter or separator in the value of String so you need a different approach to get values out of it with character functions.&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 14:57:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-parse-through-a-string/m-p/738925#M230558</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-04T14:57:52Z</dc:date>
    </item>
  </channel>
</rss>

