<?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 to align two variables and make each values a variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-align-two-variables-and-make-each-values-a-variable/m-p/721172#M223471</link>
    <description>Also, I think the transpose statement will switch rows and columns so, some variables will be in the columns more than one time since some students took common questions. In the example that I posted q_12456 is a common question and it appears once in the data.</description>
    <pubDate>Tue, 23 Feb 2021 02:51:43 GMT</pubDate>
    <dc:creator>dustychair</dc:creator>
    <dc:date>2021-02-23T02:51:43Z</dc:date>
    <item>
      <title>How to align two variables and make each values a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-align-two-variables-and-make-each-values-a-variable/m-p/721053#M223405</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I hope I can explain what I want. I have a data set that includes question ids and students' responses to those questions. As seen below, question_id has 15 characters. The question_id variable needs to be separated into 5 characters and the response variable needs to be separated into 1 character. This part was easy, I used substr and it worked.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to make each question_ids a variable and align them with their responses. I don't know how to do it. Could you help me with that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;student_id question_id response&lt;/P&gt;
&lt;P&gt;101 124541245512456 110&lt;/P&gt;
&lt;P&gt;102 124561282512828 010&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Want&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="89"&gt;
&lt;P&gt;student_id&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;q_12454&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;q_12455&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;q_12456&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="112"&gt;
&lt;P&gt;q_12825&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="67"&gt;
&lt;P&gt;q_12828&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="89"&gt;
&lt;P&gt;101&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="112"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="67"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="89"&gt;
&lt;P&gt;102&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="112"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="67"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Mon, 22 Feb 2021 20:37:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-align-two-variables-and-make-each-values-a-variable/m-p/721053#M223405</guid>
      <dc:creator>dustychair</dc:creator>
      <dc:date>2021-02-22T20:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to align two variables and make each values a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-align-two-variables-and-make-each-values-a-variable/m-p/721100#M223428</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22174"&gt;@dustychair&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I hope I can explain what I want. I have a data set that includes question ids and students' responses to those questions. As seen below, question_id has 15 characters. The question_id variable needs to be separated into 5 characters and the response variable needs to be separated into 1 character. This part was easy, I used substr and it worked.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to make each question_ids a variable and align them with their responses. I don't know how to do it. Could you help me with that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;student_id question_id response&lt;/P&gt;
&lt;P&gt;101 124541245512456 110&lt;/P&gt;
&lt;P&gt;102 124561282512828 010&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Want&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="89"&gt;
&lt;P&gt;student_id&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;q_12454&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;q_12455&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;q_12456&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="112"&gt;
&lt;P&gt;q_12825&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="67"&gt;
&lt;P&gt;q_12828&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="89"&gt;
&lt;P&gt;101&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="112"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="67"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="89"&gt;
&lt;P&gt;102&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="112"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="67"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;One way: assumes you want the values to be numeric. If not then use r= subst(response,i,1);&lt;/P&gt;
&lt;PRE&gt;data have;
 input student_id $ question_id : $15. response :$3.;
datalines;
101 124541245512456 110
102 124561282512828 010
;

data need;
   set have;
   do i=1 to 3;
      qid = cats('q_', substr(question_id,((i-1)*5 +1),5));
      r= input(substr(response,i,1),best.);
      output;
   end;
   keep student_id qid r;
run;

proc transpose data= need
   out=want (drop=_name_)
;
   by student_id;
   id qid;
   var r;
run;
&lt;/PRE&gt;
&lt;P&gt;Caveat: if your "values" are ever more than 1 character out of that string then this gets WAY complicated as you need to provide exactly which "variable" may have the 2 character and conditionally extract 2 characters from the response. If your "response" changes lengths when the 2 character value appears then you may have some extremely long coding to address the change.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Comment: Beat the @#$%@#$% out of anyone that provides data in that sort of format.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2021 21:58:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-align-two-variables-and-make-each-values-a-variable/m-p/721100#M223428</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-02-22T21:58:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to align two variables and make each values a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-align-two-variables-and-make-each-values-a-variable/m-p/721168#M223468</link>
      <description>Thank you for your response &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;. I am getting this error:&lt;BR /&gt;ERROR: The ID value "q_" occurs twice in the same BY group.&lt;BR /&gt;</description>
      <pubDate>Tue, 23 Feb 2021 02:34:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-align-two-variables-and-make-each-values-a-variable/m-p/721168#M223468</guid>
      <dc:creator>dustychair</dc:creator>
      <dc:date>2021-02-23T02:34:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to align two variables and make each values a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-align-two-variables-and-make-each-values-a-variable/m-p/721172#M223471</link>
      <description>Also, I think the transpose statement will switch rows and columns so, some variables will be in the columns more than one time since some students took common questions. In the example that I posted q_12456 is a common question and it appears once in the data.</description>
      <pubDate>Tue, 23 Feb 2021 02:51:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-align-two-variables-and-make-each-values-a-variable/m-p/721172#M223471</guid>
      <dc:creator>dustychair</dc:creator>
      <dc:date>2021-02-23T02:51:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to align two variables and make each values a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-align-two-variables-and-make-each-values-a-variable/m-p/721205#M223492</link>
      <description>&lt;P&gt;When i saw the "data" you have, my first thought was: if this is not homework, then somebody must take care of the person who "designed" this data structure, asap.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If student_id is not unique, please show what the result should look like in such case.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 08:08:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-align-two-variables-and-make-each-values-a-variable/m-p/721205#M223492</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-02-23T08:08:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to align two variables and make each values a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-align-two-variables-and-make-each-values-a-variable/m-p/721287#M223545</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22174"&gt;@dustychair&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you for your response &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;. I am getting this error:&lt;BR /&gt;ERROR: The ID value "q_" occurs twice in the same BY group.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Provide data. It doesn't for your example.&lt;/P&gt;
&lt;P&gt;If your example is incomplete then the solution is likely to be incomplete.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 15:06:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-align-two-variables-and-make-each-values-a-variable/m-p/721287#M223545</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-02-23T15:06:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to align two variables and make each values a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-align-two-variables-and-make-each-values-a-variable/m-p/721304#M223555</link>
      <description>&lt;P&gt;I attached an example of data for just 3 people. I have 1.5 million responses like that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 15:36:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-align-two-variables-and-make-each-values-a-variable/m-p/721304#M223555</guid>
      <dc:creator>dustychair</dc:creator>
      <dc:date>2021-02-23T15:36:46Z</dc:date>
    </item>
  </channel>
</rss>

