<?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: ID variable in proc transpose has multiple values per record in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/ID-variable-in-proc-transpose-has-multiple-values-per-record/m-p/957195#M373678</link>
    <description>Sorry to further clarify, in response to if response is the number of choice selected then no it is not. For example for record ID 1, the question 38912 was a multiple choice question with response options of 1-10, and record ID 1 chose response option 2, 9, and 10. These numbers correspond to categories that are in a data dictionary elsewhere.</description>
    <pubDate>Fri, 24 Jan 2025 22:22:23 GMT</pubDate>
    <dc:creator>mitrakos</dc:creator>
    <dc:date>2025-01-24T22:22:23Z</dc:date>
    <item>
      <title>ID variable in proc transpose has multiple values per record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ID-variable-in-proc-transpose-has-multiple-values-per-record/m-p/957186#M373672</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;This might be a little confusing to explain so I will try my best. I have a survey with around ~1000 records that I'm trying to transpose from long to wide, the problem is that three questions in the survey has two questions that can have multiple options selected, and when I use proc transpose with let option it only captures one of the options. I'm unsure of how to have all the responses shown for each record ID, and doing it manually will take a very long time. I've included some sample data of what I'm looking at, my code thus far, and my desired output. Thank you so much!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sample dataset of what I have:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input record_id labcode $ protocolcode $ question_value response date :MMDDYY10.;
format date date9.;
datalines;
1 Lab1 P1 38912 2 1/30/2020
1 Lab1 P1 38912 9 1/30/2020
1 Lab1 P1 38912 10 1/30/2020
1 Lab1 P1 60388 5 1/30/2020
1 Lab1 P1 60388 1 1/30/2020
2 Lab2 P3 47577 1 2/15/2015
2 Lab2 P3 47577 2 2/15/2015
2 Lab2 P3 47577 3 2/15/2015
2 Lab2 P3 38912 9 2/15/2015
2 Lab2 P3 38912 10 2/15/2015
3 Lab5 P5 60388 1 6/23/2021
3 Lab5 P5 60388 2 6/23/2021
3 Lab5 P5 38912 8 6/23/2021
3 Lab5 P5 38912 10 6/23/2021
3 Lab5 P5 38912 7 6/23/2021
4 Lab4 P6 38912 9 3/12/2014
4 Lab4 P6 38912 3 3/12/2014
4 Lab4 P6 47577 4 3/12/2014
4 Lab4 P6 47577 5 3/12/2014
4 Lab4 P6 47577 1 3/12/2014
5 Lab9 P8 38912 10 7/6/2020
5 Lab9 P8 38912 9 7/6/2020
5 Lab9 P8 38912 8 7/6/2020
5 Lab9 P8 60388 1 7/6/2020
5 Lab9 P8 60388 5 7/6/2020
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My transpose code so far:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options validvarname=v7;
proc transpose data=have out = want name=masterquestioncore let;
by record_id labcode protocolcode date; *i need all of these to show up in final dataset so I have them in the sort statement;
var response;
id question_value ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here's a table showing my desired output, I am essentially looking for one record ID per row, with the question_values each their own variable and repeats are named as such:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="10%" height="30px"&gt;record_Id&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;labcode&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;protocolcode&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;38912_1&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;38912_2&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;38912_3&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;60388_1&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;60388_2&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;47577_1&lt;/TD&gt;
&lt;TD width="5%" height="30px"&gt;47577_2&lt;/TD&gt;
&lt;TD width="2.5%"&gt;47577_3&lt;/TD&gt;
&lt;TD width="2.5%"&gt;date&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="10%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;Lab1&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;P1&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;2&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;9&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;10&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;5&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="5%" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="2.5%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="2.5%"&gt;1/30/2020&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="10%" height="30px"&gt;2&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;Lab2&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;P3&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;9&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;10&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="5%" height="30px"&gt;2&lt;/TD&gt;
&lt;TD width="2.5%"&gt;3&lt;/TD&gt;
&lt;TD width="2.5%"&gt;2/15/2015&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="10%" height="30px"&gt;3&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;Lab5&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;P5&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;8&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;7&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;10&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;2&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="5%" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="2.5%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="2.5%"&gt;6/23/2021&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="10%" height="30px"&gt;4&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;Lab4&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;P6&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;9&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;3&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;4&lt;/TD&gt;
&lt;TD width="5%" height="30px"&gt;5&lt;/TD&gt;
&lt;TD width="2.5%"&gt;1&lt;/TD&gt;
&lt;TD width="2.5%"&gt;3/12/2014&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="10%" height="30px"&gt;5&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;Lab9&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;P8&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;10&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;9&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;5&lt;/TD&gt;
&lt;TD width="10%" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="5%" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="2.5%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="2.5%"&gt;7/6/2020&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hopefully I have explained it well enough. There are multiple other question_value variables that are other items on the survey, but they are all only one response per record_id, so those are easy to transpose, it is just these that are complicated. Thank you again!&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jan 2025 21:26:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ID-variable-in-proc-transpose-has-multiple-values-per-record/m-p/957186#M373672</guid>
      <dc:creator>mitrakos</dc:creator>
      <dc:date>2025-01-24T21:26:11Z</dc:date>
    </item>
    <item>
      <title>Re: ID variable in proc transpose has multiple values per record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ID-variable-in-proc-transpose-has-multiple-values-per-record/m-p/957192#M373675</link>
      <description>&lt;P&gt;Are these multiple choice questions?&amp;nbsp; Something like select ALL that apply and the "RESPONSE" variable is the number of the choice selected?&lt;/P&gt;
&lt;P&gt;If so then use the question and the response in the ID statement add an extra variable to use the VAR statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort;
  by record_id labcode protocolcode date question_value response;
run;

data for_transpose;
  set have;
  picked='X';
run;

proc transpose data=for_transpose prefix=Q delim=_ out=wide(drop=_name_);
  by record_id labcode protocolcode date;
  id question_value response;
  var picked;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;                  p
                  r
                  o
     r            t                            Q
     e            o                  Q    Q    3    Q    Q    Q    Q    Q    Q    Q    Q    Q    Q    Q
     c     l      c                  3    3    8    6    6    4    4    4    3    3    6    3    4    4
     o     a      o                  8    8    9    0    0    7    7    7    8    8    0    8    7    7
     r     b      l                  9    9    1    3    3    5    5    5    9    9    3    9    5    5
     d     c      c         d        1    1    2    8    8    7    7    7    1    1    8    1    7    7
O    _     o      o         a        2    2    _    8    8    7    7    7    2    2    8    2    7    7
b    i     d      d         t        _    _    1    _    _    _    _    _    _    _    _    _    _    _
s    d     e      e         e        2    9    0    1    5    1    2    3    7    8    2    3    4    5

1    1    Lab1    P1    30JAN2020    X    X    X    X    X
2    2    Lab2    P3    15FEB2015         X    X              X    X    X
3    3    Lab5    P5    23JUN2021              X    X                        X    X    X
4    4    Lab4    P6    12MAR2014         X                   X                             X    X    X
5    5    Lab9    P8    06JUL2020         X    X    X    X                        X
&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Jan 2025 22:14:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ID-variable-in-proc-transpose-has-multiple-values-per-record/m-p/957192#M373675</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-01-24T22:14:43Z</dc:date>
    </item>
    <item>
      <title>Re: ID variable in proc transpose has multiple values per record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ID-variable-in-proc-transpose-has-multiple-values-per-record/m-p/957193#M373676</link>
      <description>&lt;P&gt;If the values are free text the add an extra variable to indicate which replicate it is and include that new varaible in the ID statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data for_transpose;
  do rep=1 by 1 until(last.date);
    set have;
    by record_id labcode protocolcode date;
    output;
  end;
run;

proc transpose data=for_transpose prefix=Q delim=_ out=wide(drop=_name_);
  by record_id labcode protocolcode date;
  id question_value rep;
  var response;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;                  p
                  r
                  o
     r            t
     e            o                   Q    Q     Q    Q    Q    Q    Q    Q     Q     Q    Q    Q    Q    Q
     c     l      c                   3    3     3    6    6    4    4    4     3     3    6    6    4    4
     o     a      o                   8    8     8    0    0    7    7    7     8     8    0    0    7    7
     r     b      l                   9    9     9    3    3    5    5    5     9     9    3    3    5    5
     d     c      c         d         1    1     1    8    8    7    7    7     1     1    8    8    7    7
O    _     o      o         a         2    2     2    8    8    7    7    7     2     2    8    8    7    7
b    i     d      d         t         _    _     _    _    _    _    _    _     _     _    _    _    _    _
s    d     e      e         e         1    2     3    4    5    1    2    3     4     5    1    2    4    5

1    1    Lab1    P1    30JAN2020     2    9    10    5    1    .    .    .     .     .    .    .    .    .
2    2    Lab2    P3    15FEB2015     .    .     .    .    .    1    2    3     9    10    .    .    .    .
3    3    Lab5    P5    23JUN2021     .    .     8    .    .    .    .    .    10     7    1    2    .    .
4    4    Lab4    P6    12MAR2014     9    3     .    .    .    .    .    4     .     .    .    .    5    1
5    5    Lab9    P8    06JUL2020    10    9     8    1    5    .    .    .     .     .    .    .    .    .
&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Jan 2025 22:17:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ID-variable-in-proc-transpose-has-multiple-values-per-record/m-p/957193#M373676</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-01-24T22:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: ID variable in proc transpose has multiple values per record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ID-variable-in-proc-transpose-has-multiple-values-per-record/m-p/957194#M373677</link>
      <description>They are multiple choice yes, and these specific questions I'm having trouble with are a "select all that apply" type question. Ideally I would like to have the response value in the cell rather than an X since this dataset will be uploaded elsewhere where the value is needed in the cell.</description>
      <pubDate>Fri, 24 Jan 2025 22:20:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ID-variable-in-proc-transpose-has-multiple-values-per-record/m-p/957194#M373677</guid>
      <dc:creator>mitrakos</dc:creator>
      <dc:date>2025-01-24T22:20:02Z</dc:date>
    </item>
    <item>
      <title>Re: ID variable in proc transpose has multiple values per record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ID-variable-in-proc-transpose-has-multiple-values-per-record/m-p/957195#M373678</link>
      <description>Sorry to further clarify, in response to if response is the number of choice selected then no it is not. For example for record ID 1, the question 38912 was a multiple choice question with response options of 1-10, and record ID 1 chose response option 2, 9, and 10. These numbers correspond to categories that are in a data dictionary elsewhere.</description>
      <pubDate>Fri, 24 Jan 2025 22:22:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ID-variable-in-proc-transpose-has-multiple-values-per-record/m-p/957195#M373678</guid>
      <dc:creator>mitrakos</dc:creator>
      <dc:date>2025-01-24T22:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: ID variable in proc transpose has multiple values per record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ID-variable-in-proc-transpose-has-multiple-values-per-record/m-p/957198#M373679</link>
      <description>&lt;P&gt;Then you can use the existing dataset directly.&amp;nbsp; Just use RESPONSE in both the ID and VAR statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have prefix=Q delim=_ out=wide(drop=_name_);
  by record_id labcode protocolcode date;
  id question_value response;
  var response;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1737757609817.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/103989i21FFD2106AC6FB91/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1737757609817.png" alt="Tom_0-1737757609817.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jan 2025 22:27:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ID-variable-in-proc-transpose-has-multiple-values-per-record/m-p/957198#M373679</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-01-24T22:27:58Z</dc:date>
    </item>
    <item>
      <title>Re: ID variable in proc transpose has multiple values per record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ID-variable-in-proc-transpose-has-multiple-values-per-record/m-p/957199#M373680</link>
      <description>Oh my god you are a lifesaver!! Thank you so much for this.</description>
      <pubDate>Fri, 24 Jan 2025 22:31:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ID-variable-in-proc-transpose-has-multiple-values-per-record/m-p/957199#M373680</guid>
      <dc:creator>mitrakos</dc:creator>
      <dc:date>2025-01-24T22:31:12Z</dc:date>
    </item>
  </channel>
</rss>

