<?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 select specific values in a string? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-select-specific-values-in-a-string/m-p/254542#M48562</link>
    <description>&lt;P&gt;I am using this array again for a similar purpose, and need some additional help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;lt;The SUBSTR function call has too many arguments.&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This time, the string is a maximum of 6 characters. Each value is 2 characters. In other words, a value of&amp;nbsp;010101 has 3 distinct values (01, 01, 01).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ultimately, I want to create 3 new variables for each string:&lt;/P&gt;
&lt;P&gt;IF VAR1=01 THEN NEW_VAR1=1;&amp;nbsp;ELSE NEW_VAR1=0;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IF VAR2=01 THEN NEW_VAR2=1; ELSE NEW_VAR2=0;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code works for one variable:&lt;/P&gt;
&lt;PRE&gt;DATA want;
	SET have;
	
	ARRAY answers (*) $ 2 VAR1-VAR3;
	DO i = 1 to 3;
	answers(i) = substr(_400203, i, 2);
	END;
	
	DROP 
	_400203
	i;
RUN; &lt;/PRE&gt;
&lt;P&gt;But this code does not work for multiple variables (In this example there are only 2 variables (_400203 and_400204), but I want to use it w/ 44 variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;lt;The SUBSTR function call has too many arguments.&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DATA want;
SET&amp;nbsp;have

ARRAY array_name&amp;nbsp;(*) $ 2 VAR1-VAR6;
DO i = 1 to 6;
answers(i) = substr(_400203-_400204, i, 2);
END;

DROP 
_400203
_400204
i;
RUN;&lt;/PRE&gt;</description>
    <pubDate>Fri, 04 Mar 2016 17:27:03 GMT</pubDate>
    <dc:creator>_maldini_</dc:creator>
    <dc:date>2016-03-04T17:27:03Z</dc:date>
    <item>
      <title>How do I select specific values in a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-select-specific-values-in-a-string/m-p/251420#M47499</link>
      <description>&lt;P&gt;I have a variable that contains a string of 9 numbers&amp;nbsp;as values&amp;nbsp;(e.g. 0000000100, 1110000100, etc.). These 9 numbers represent individual values (1 or 0). They were generated by a survey using radio buttons. If there is a&amp;nbsp;1 in the first position, it indicates a "Yes" to question number 1. If there is a&amp;nbsp;0&amp;nbsp;in the second&amp;nbsp;position, it indicates a "No" to question number 2.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to create 9 new variables from each of the&amp;nbsp;values in the string.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Var1 will get a 1 if the value in position one is 1. It will get a 0 if the value in position one is 0.&lt;/P&gt;
&lt;P&gt;Var2 will get a 1 if the value in position 2 is 1. Etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I select specific values in a string like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I apologize if my description is unclear. I am a relative novice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Feb 2016 18:24:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-select-specific-values-in-a-string/m-p/251420#M47499</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2016-02-21T18:24:47Z</dc:date>
    </item>
    <item>
      <title>Re: How do I select specific values in a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-select-specific-values-in-a-string/m-p/251424#M47501</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  answer_string = '101010101';
  array answers (*) $ 1 A1-A9;
  do i = 1 to 9;
    answers(i) = substr(answer_string, i, 1);
  end;
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 21 Feb 2016 18:41:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-select-specific-values-in-a-string/m-p/251424#M47501</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2016-02-21T18:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: How do I select specific values in a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-select-specific-values-in-a-string/m-p/251442#M47508</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi﻿&lt;/a&gt;. Can I ask you a few clarifying questions?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&amp;lt;answer_string = '101010101';&amp;gt; &amp;nbsp;Does this define the name of the string? And the value? The actual value of the string is different for each observation. Subject 1 might have&amp;nbsp;101010101 while subject 2 might have 000010101. Do I need to account for that in this line?&lt;/LI&gt;
&lt;LI&gt;What does the 1 in the array represent (After the $ and before the elements, A1-A9)?&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Mon, 22 Feb 2016 00:15:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-select-specific-values-in-a-string/m-p/251442#M47508</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2016-02-22T00:15:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do I select specific values in a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-select-specific-values-in-a-string/m-p/251448#M47513</link>
      <description>&lt;OL&gt;
&lt;LI&gt;Yes. I assigned it just one value so you could understand the solution more easily. Of course it changes for each observation. Do you already have a dataset with this string in it? If you do then just read it in with a SET statement.&lt;/LI&gt;
&lt;LI&gt;The 1 is the length of the variables A1 to A9 - one character.&amp;nbsp;&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Mon, 22 Feb 2016 02:13:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-select-specific-values-in-a-string/m-p/251448#M47513</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2016-02-22T02:13:47Z</dc:date>
    </item>
    <item>
      <title>Re: How do I select specific values in a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-select-specific-values-in-a-string/m-p/251451#M47516</link>
      <description>&lt;P&gt;&amp;lt;I assigned it just one value so you could understand the solution more easily.&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Got it.&amp;nbsp;I guess I'm still not clear what to put here if the values are different from observation to observation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, I do have the data set and was planning on reading it in w/ a SET statement.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2016 02:20:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-select-specific-values-in-a-string/m-p/251451#M47516</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2016-02-22T02:20:25Z</dc:date>
    </item>
    <item>
      <title>Re: How do I select specific values in a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-select-specific-values-in-a-string/m-p/251486#M47533</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  array answers (*) $ 1 A1-A9;
  do i = 1 to 9;
    answers(i) = substr(answer_string, i, 1);
  end;
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Feb 2016 07:53:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-select-specific-values-in-a-string/m-p/251486#M47533</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2016-02-22T07:53:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do I select specific values in a string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-select-specific-values-in-a-string/m-p/254542#M48562</link>
      <description>&lt;P&gt;I am using this array again for a similar purpose, and need some additional help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;lt;The SUBSTR function call has too many arguments.&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This time, the string is a maximum of 6 characters. Each value is 2 characters. In other words, a value of&amp;nbsp;010101 has 3 distinct values (01, 01, 01).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ultimately, I want to create 3 new variables for each string:&lt;/P&gt;
&lt;P&gt;IF VAR1=01 THEN NEW_VAR1=1;&amp;nbsp;ELSE NEW_VAR1=0;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IF VAR2=01 THEN NEW_VAR2=1; ELSE NEW_VAR2=0;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code works for one variable:&lt;/P&gt;
&lt;PRE&gt;DATA want;
	SET have;
	
	ARRAY answers (*) $ 2 VAR1-VAR3;
	DO i = 1 to 3;
	answers(i) = substr(_400203, i, 2);
	END;
	
	DROP 
	_400203
	i;
RUN; &lt;/PRE&gt;
&lt;P&gt;But this code does not work for multiple variables (In this example there are only 2 variables (_400203 and_400204), but I want to use it w/ 44 variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;lt;The SUBSTR function call has too many arguments.&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DATA want;
SET&amp;nbsp;have

ARRAY array_name&amp;nbsp;(*) $ 2 VAR1-VAR6;
DO i = 1 to 6;
answers(i) = substr(_400203-_400204, i, 2);
END;

DROP 
_400203
_400204
i;
RUN;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Mar 2016 17:27:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-select-specific-values-in-a-string/m-p/254542#M48562</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2016-03-04T17:27:03Z</dc:date>
    </item>
  </channel>
</rss>

