<?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 Creating dummy variables for one character variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-dummy-variables-for-one-character-variable/m-p/63206#M13743</link>
    <description>I would like to convert a variable that combined all information about requirements for each statement and we need to make about 30 dummy variables (this is the number of special requirements). We have two types of such requirements: regular (R) and special (S). Every statement has R requirement(s) but not every has S requirements. For example for a statement: &lt;B&gt;!&lt;/B&gt;S3, 4 &lt;B&gt;!&lt;/B&gt;R22  which means this statement has two special requirements (#3 and #4) and one regular requirement (#22). Based on such information I need to convert it to S1=0, S2=0, &lt;B&gt;S3=1, S4=1&lt;/B&gt;. S5=0 and R1=0, R2=0, ..., R21=0, &lt;B&gt;R22=1&lt;/B&gt;, R23=0, ..., R25=0.&lt;BR /&gt;
Note. the code for the type of requirement starts with &lt;B&gt;!&lt;/B&gt; and separate among the requirement of same type by a comma and between the two types of requirements by a space.&lt;BR /&gt;
&lt;BR /&gt;
Could you please help me achieve such task?</description>
    <pubDate>Mon, 17 Jan 2011 14:13:52 GMT</pubDate>
    <dc:creator>SASEG</dc:creator>
    <dc:date>2011-01-17T14:13:52Z</dc:date>
    <item>
      <title>Creating dummy variables for one character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-dummy-variables-for-one-character-variable/m-p/63206#M13743</link>
      <description>I would like to convert a variable that combined all information about requirements for each statement and we need to make about 30 dummy variables (this is the number of special requirements). We have two types of such requirements: regular (R) and special (S). Every statement has R requirement(s) but not every has S requirements. For example for a statement: &lt;B&gt;!&lt;/B&gt;S3, 4 &lt;B&gt;!&lt;/B&gt;R22  which means this statement has two special requirements (#3 and #4) and one regular requirement (#22). Based on such information I need to convert it to S1=0, S2=0, &lt;B&gt;S3=1, S4=1&lt;/B&gt;. S5=0 and R1=0, R2=0, ..., R21=0, &lt;B&gt;R22=1&lt;/B&gt;, R23=0, ..., R25=0.&lt;BR /&gt;
Note. the code for the type of requirement starts with &lt;B&gt;!&lt;/B&gt; and separate among the requirement of same type by a comma and between the two types of requirements by a space.&lt;BR /&gt;
&lt;BR /&gt;
Could you please help me achieve such task?</description>
      <pubDate>Mon, 17 Jan 2011 14:13:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-dummy-variables-for-one-character-variable/m-p/63206#M13743</guid>
      <dc:creator>SASEG</dc:creator>
      <dc:date>2011-01-17T14:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables for one character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-dummy-variables-for-one-character-variable/m-p/63207#M13744</link>
      <description>Lookup the scan function. &lt;BR /&gt;
&lt;BR /&gt;
s_comp=scan (var, 1, "!");&lt;BR /&gt;
r_comp=scan(var, 2, "!");&lt;BR /&gt;
&lt;BR /&gt;
This assumes that R and S are always in the order stated.&lt;BR /&gt;
&lt;BR /&gt;
Use it once to separate the S and R components into separate strings, then in each string you can scan or using "S," or "R," as the delimiter and a loop to get the numbers.</description>
      <pubDate>Mon, 17 Jan 2011 23:27:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-dummy-variables-for-one-character-variable/m-p/63207#M13744</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2011-01-17T23:27:54Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables for one character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-dummy-variables-for-one-character-variable/m-p/63208#M13745</link>
      <description>I agree with Reeza, and suggest the "input record buffer" be parsed using one of a few different DATA step functions, likely considering maybe SCAN, FIND, SUBSTR, INDEX, INDEXC, and possibly VVALUE or VVALUEX for assignment.  &lt;BR /&gt;
&lt;BR /&gt;
Suggested DATA step structure approach demonstrated below:&lt;BR /&gt;
&lt;BR /&gt;
DATA ;&lt;BR /&gt;
KEEP ....;&lt;BR /&gt;
* RECOMMEND CODING SAS ATTRIB OR LENGTH STATEMENTS ;&lt;BR /&gt;
*   HERE  TO DECLARE EXPECTED SAS VARIABLES.                           ;&lt;BR /&gt;
INFILE ....;&lt;BR /&gt;
INPUT ;&lt;BR /&gt;
DO WHILE(1=1);&lt;BR /&gt;
  * COME HERE FOR INFINITE LOOP TO PARSE CURRENT INPUT  ;&lt;BR /&gt;
  * RECORD AND DECODE ONE OR MORE SUB-FIELDS.                ;&lt;BR /&gt;
  LENGTH TEMPVAR $1000;&lt;BR /&gt;
  I+1; &lt;BR /&gt;
  TEMPVAR = SCAN(_INFILE_,I,'!');&lt;BR /&gt;
  * EXIT THE DO LOOP NOW WHEN NO MORE FIELDS TO PARSE. ;&lt;BR /&gt;
  IF TEMPVAR = ' ' THEN LEAVE;&lt;BR /&gt;
  * YOUR PARSING CODE FOR EACH RECORD SUBTYPE/FIELDS GOES HERE.;&lt;BR /&gt;
END;&lt;BR /&gt;
RUN;</description>
      <pubDate>Mon, 17 Jan 2011 23:54:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-dummy-variables-for-one-character-variable/m-p/63208#M13745</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2011-01-17T23:54:43Z</dc:date>
    </item>
  </channel>
</rss>

