<?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: proc transpose ID value occurs twice in same BY group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose-ID-value-occurs-twice-in-same-BY-group/m-p/856365#M338371</link>
    <description>&lt;P&gt;I can't post the entire thing. Communites.sas.com says it's too long; plus, I had to force clear the window in SAS because it was too long for my window.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Other than what I already pasted before, here's the other information:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ERROR: The ID value "a17" occurs twice in the same BY group.
ERROR: The ID value "a17" occurs twice in the same BY group.
ERROR: The ID value "a17" occurs twice in the same BY group.
ERROR: The ID value "a17" occurs twice in the same BY group.
ERROR: The ID value "a17" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
      entry_count=9
ERROR: The ID value "a10" occurs twice in the same BY group.
ERROR: The ID value "a10" occurs twice in the same BY group.
ERROR: Too many bad BY groups.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 317016 observations read from the data set DATA.
WARNING: The data set WORK.WIDE may be incomplete.  When this step was stopped there were 0
         observations and 0 variables.
WARNING: Data set WORK.WIDE was not replaced because this step was stopped.
NOTE: PROCEDURE TRANSPOSE used (Total process time):
      real time           1:07:21.06
      cpu time            1:17.46
&lt;/PRE&gt;</description>
    <pubDate>Mon, 30 Jan 2023 22:40:19 GMT</pubDate>
    <dc:creator>confooseddesi89</dc:creator>
    <dc:date>2023-01-30T22:40:19Z</dc:date>
    <item>
      <title>proc transpose ID value occurs twice in same BY group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose-ID-value-occurs-twice-in-same-BY-group/m-p/856342#M338360</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am having an issue running proc transpose on my data. Below are sample data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="678"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;ID&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;Variable&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="155"&gt;
&lt;P&gt;&lt;STRONG&gt;Variable_Num&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="155"&gt;
&lt;P&gt;&lt;STRONG&gt;question_text_short&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;answer&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;entry_count&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Gen_Health&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="155"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="155"&gt;
&lt;P&gt;General health&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Fair&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Gen_Health&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="155"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="155"&gt;
&lt;P&gt;General health&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Fair&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Gen_Health&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="155"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="155"&gt;
&lt;P&gt;General health&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Fair&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;GAD&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="155"&gt;
&lt;P&gt;83&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="155"&gt;
&lt;P&gt;Anxiety&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Several days&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;GAD&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="155"&gt;
&lt;P&gt;83&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="155"&gt;
&lt;P&gt;Anxiety&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Some days&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;GAD&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="155"&gt;
&lt;P&gt;83&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="155"&gt;
&lt;P&gt;Anxiety&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Every day&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;PSS&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="155"&gt;
&lt;P&gt;69&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="155"&gt;
&lt;P&gt;Stress&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Sometimes&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;PSS&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="155"&gt;
&lt;P&gt;69&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="155"&gt;
&lt;P&gt;Stress&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Sometimes&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;PSS&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="155"&gt;
&lt;P&gt;69&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="155"&gt;
&lt;P&gt;Stress&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;Never&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you can see, the variable_num corresponds to the Variable. Entry_count refers to the time of the entry. I want each Variable to be a separate column. In other words, I want the data structure to be the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="56.92604049864061%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="7%" height="30px"&gt;
&lt;P&gt;&lt;STRONG&gt;ID&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="23%" height="30px"&gt;
&lt;P&gt;&lt;STRONG&gt;entry_count&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;
&lt;P&gt;&lt;STRONG&gt;Gen_Health&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="27.901098901098905%" height="30px"&gt;
&lt;P&gt;&lt;STRONG&gt;GAD&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="4.098901098901097%" height="30px"&gt;
&lt;P&gt;&lt;STRONG&gt;PSS&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="7%" height="30px"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="23%" height="30px"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;
&lt;P&gt;Fair&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="27.901098901098905%" height="30px"&gt;
&lt;P&gt;Several days&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="4.098901098901097%" height="30px"&gt;
&lt;P&gt;Sometimes&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="7%" height="30px"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="23%" height="30px"&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;
&lt;P&gt;Fair&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="27.901098901098905%" height="30px"&gt;
&lt;P&gt;Some days&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="4.098901098901097%" height="30px"&gt;
&lt;P&gt;Sometimes&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="7%" height="22px"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="23%" height="22px"&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="12.5%" height="22px"&gt;
&lt;P&gt;Fair&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="27.901098901098905%" height="22px"&gt;
&lt;P&gt;Every day&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="4.098901098901097%" height="22px"&gt;
&lt;P&gt;Never&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My code is the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=data out=wide prefix=answer;
    by entry_count;
    id Variable;
    var answer;
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;But the log fills with errors such as "ERROR: The ID value "answerGAD" occurs twice in the same BY group." No dataset is produced. I tried both "Variable" and "Variable_Num" for the "id" in the code. Can someone assist? I even tried shortening the prefix to "a" after reading another message on this forum that the prefix was too long, but I still get the same error. Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2023 21:19:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-transpose-ID-value-occurs-twice-in-same-BY-group/m-p/856342#M338360</guid>
      <dc:creator>confooseddesi89</dc:creator>
      <dc:date>2023-01-30T21:19:13Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose ID value occurs twice in same BY group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose-ID-value-occurs-twice-in-same-BY-group/m-p/856355#M338364</link>
      <description>&lt;P&gt;Change the sort order to ID Entry_count and use the following:&lt;/P&gt;
&lt;PRE&gt;proc transpose data=data out=wide ;
    by id entry_count;
    id Variable;
    idlabel question_text_short;
    var answer;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Jan 2023 22:18:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-transpose-ID-value-occurs-twice-in-same-BY-group/m-p/856355#M338364</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-01-30T22:18:27Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose ID value occurs twice in same BY group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose-ID-value-occurs-twice-in-same-BY-group/m-p/856360#M338368</link>
      <description>&lt;P&gt;EDITED: Never mind, I had forgotten a semicolon! ballardw's solution worked!&lt;/P&gt;
&lt;DIV id="tinyMceEditorconfooseddesi89_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Upon running the code, I get the following error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: Variable IDLABEL not found.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems as though SAS does not recognize the IDLABEL command.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2023 23:16:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-transpose-ID-value-occurs-twice-in-same-BY-group/m-p/856360#M338368</guid>
      <dc:creator>confooseddesi89</dc:creator>
      <dc:date>2023-01-30T23:16:58Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose ID value occurs twice in same BY group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose-ID-value-occurs-twice-in-same-BY-group/m-p/856363#M338369</link>
      <description>&lt;P&gt;Show us the ENTIRE log for PROC TRANSPOSE. Please copy the log as text and paste it into the window that appears when you click on the &amp;lt;/&amp;gt; icon. Always (that's ALWAYS) do this when you have an error in the log.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PaigeMiller_0-1663012019648.png" style="width: 859px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75161i0E71B1489A6C9839/image-size/large?v=v2&amp;amp;px=999" role="button" title="PaigeMiller_0-1663012019648.png" alt="PaigeMiller_0-1663012019648.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2023 22:32:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-transpose-ID-value-occurs-twice-in-same-BY-group/m-p/856363#M338369</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-30T22:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose ID value occurs twice in same BY group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose-ID-value-occurs-twice-in-same-BY-group/m-p/856365#M338371</link>
      <description>&lt;P&gt;I can't post the entire thing. Communites.sas.com says it's too long; plus, I had to force clear the window in SAS because it was too long for my window.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Other than what I already pasted before, here's the other information:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ERROR: The ID value "a17" occurs twice in the same BY group.
ERROR: The ID value "a17" occurs twice in the same BY group.
ERROR: The ID value "a17" occurs twice in the same BY group.
ERROR: The ID value "a17" occurs twice in the same BY group.
ERROR: The ID value "a17" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
      entry_count=9
ERROR: The ID value "a10" occurs twice in the same BY group.
ERROR: The ID value "a10" occurs twice in the same BY group.
ERROR: Too many bad BY groups.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 317016 observations read from the data set DATA.
WARNING: The data set WORK.WIDE may be incomplete.  When this step was stopped there were 0
         observations and 0 variables.
WARNING: Data set WORK.WIDE was not replaced because this step was stopped.
NOTE: PROCEDURE TRANSPOSE used (Total process time):
      real time           1:07:21.06
      cpu time            1:17.46
&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Jan 2023 22:40:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-transpose-ID-value-occurs-twice-in-same-BY-group/m-p/856365#M338371</guid>
      <dc:creator>confooseddesi89</dc:creator>
      <dc:date>2023-01-30T22:40:19Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose ID value occurs twice in same BY group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose-ID-value-occurs-twice-in-same-BY-group/m-p/856367#M338372</link>
      <description>&lt;P&gt;That the IDLABEL statement is mistaken for a variable name points to a missing semicolon for the preceding statement.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2023 22:55:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-transpose-ID-value-occurs-twice-in-same-BY-group/m-p/856367#M338372</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-01-30T22:55:42Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose ID value occurs twice in same BY group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose-ID-value-occurs-twice-in-same-BY-group/m-p/856373#M338375</link>
      <description>&lt;P&gt;Oh wow I feel like a you-know-what! Haha thanks! This worked great.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2023 23:15:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-transpose-ID-value-occurs-twice-in-same-BY-group/m-p/856373#M338375</guid>
      <dc:creator>confooseddesi89</dc:creator>
      <dc:date>2023-01-30T23:15:18Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose ID value occurs twice in same BY group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose-ID-value-occurs-twice-in-same-BY-group/m-p/856374#M338376</link>
      <description>&lt;P&gt;Excellent! Worked perfectly.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2023 23:15:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-transpose-ID-value-occurs-twice-in-same-BY-group/m-p/856374#M338376</guid>
      <dc:creator>confooseddesi89</dc:creator>
      <dc:date>2023-01-30T23:15:42Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose ID value occurs twice in same BY group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose-ID-value-occurs-twice-in-same-BY-group/m-p/922111#M363129</link>
      <description>&lt;P&gt;I am trying to create a wide data set with a unique DUPERSID per line and the RXNDC and RXNAME variable values&amp;nbsp; on the same row from a long data set with&amp;nbsp; DUPERSID,&amp;nbsp;RXNDC and RXNAME values&amp;nbsp; in varying number of rows. Below are my&amp;nbsp; SAS code including datalines and the SAS output.&lt;/P&gt;
&lt;PRE&gt;data testdata;
infile datalines truncover;
input DUPERSID :$10.    RXNDC  :$11.   RXNAME :$50.;
datalines;
2320018102     -15     ANTICOAGULANTS
2320018102     -15     ANTICOAGULANTS
2320038101     -15     ANTICOAGULANTS
2320038101     -15     ANTICOAGULANTS
2320038101     -15     ANTICOAGULANTS
2320105101     -15     INSULIN
2320105101     -15     INSULIN
2320105101     -15     INSULIN
2320105101     -15     INSULIN
2320222101    73070010011    INSULIN ASPA
2320222101    73070010011    INSULIN ASPA
2320222101    73070010011    INSULIN ASPA
2320222101    73070010011    INSULIN ASPA
2320222101    73070010011    INSULIN ASPA
2320222101    73070010011    INSULIN ASPA
2320222101    73070010011    INSULIN ASPA
2320222101    73070010011    INSULIN ASPA
;
proc print data=testdata; run;
proc sort data=WORK.testdata; by DUPERSID; run;

proc transpose data=testdata out=work.wide_IC prefix=RX;
 by DUPERSID ;
 var  rxndc rxname;
 run;

PROC PRINT DATA= WORK.wide_IC ;
RUN;


&lt;/PRE&gt;
&lt;P&gt;Output&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;Obs DUPERSID _NAME_ RX1 RX2 RX3 RX4 RX5 RX6 RX7 RX8&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;1 2320018102 RXNDC -15 -15&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;2 2320018102 RXNAME ANTICOAGULANTS ANTICOAGULANTS&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;3 2320038101 RXNDC -15 -15 -15&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;4 2320038101 RXNAME ANTICOAGULANTS ANTICOAGULANTS ANTICOAGULANTS&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;5 2320105101 RXNDC -15 -15 -15 -15&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;6 2320105101 RXNAME INSULIN INSULIN INSULIN INSULIN&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;7 2320222101 RXNDC 73070010011 73070010011 73070010011 73070010011 73070010011 73070010011 73070010011 73070010011&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;8 2320222101 RXNAME INSULIN INSULIN INSULIN INSULIN INSULIN INSULIN INSULIN INSULIN&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Issue: The wide data set has the RXNDC and RXNAME values in separate lines rather than the same line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To further widen the&amp;nbsp; the above output data, I used the following SAS code (with double transposition).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=WORK.wide_IC; by DUPERSID _NAME_; run;

proc transpose data=WORK.wide_IC out=work.narrow_IC ;
 by DUPERSID _NAME_ ;
 var  RX:;
run;

proc sort data=WORK.narrow_IC; by DUPERSID; run;
proc transpose data=WORK.narrow_IC out=work.wide2_IC;
 by DUPERSID ;
 var  COL1;
 id _NAME_;
 run;&lt;BR /&gt;&lt;BR /&gt;I am getting the following errors.&lt;BR /&gt;ERROR: The ID value "RXNAME" occurs twice in the same BY group.&lt;BR /&gt;ERROR: The ID value "RXNAME" occurs twice in the same BY group.&lt;BR /&gt;&lt;BR /&gt;Question:&amp;nbsp;What changes would I make to my code to create a wide data set &lt;BR /&gt;so that it will have the RXNDC and RXNAME values on same line, with &lt;BR /&gt;one DUPERSID per line?&lt;BR /&gt;&lt;BR /&gt;Any&amp;nbsp;help&amp;nbsp;will&amp;nbsp;be&amp;nbsp;appreciated.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2024 13:41:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-transpose-ID-value-occurs-twice-in-same-BY-group/m-p/922111#M363129</guid>
      <dc:creator>pkm_edu</dc:creator>
      <dc:date>2024-03-28T13:41:46Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose ID value occurs twice in same BY group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose-ID-value-occurs-twice-in-same-BY-group/m-p/922137#M363137</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/285909"&gt;@pkm_edu&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should start you own thread, possibly referencing this one. Your issue is different than the original poster.&lt;/P&gt;
&lt;P&gt;The data step shown results in values of "INSULIN" not "INSULIN ASPA".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also what will you do with the resulting data set? Typically a wide set is much harder to work with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you show exactly what you expect for output? You have so many repeated values in that example data I'm not sure that I understand what is needed or the utility of that many repeated values on an observation.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2024 15:13:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-transpose-ID-value-occurs-twice-in-same-BY-group/m-p/922137#M363137</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-03-28T15:13:05Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose ID value occurs twice in same BY group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose-ID-value-occurs-twice-in-same-BY-group/m-p/922144#M363138</link>
      <description>1)      Sorry for not starting a new thread. Do you want me to create a new thread?&lt;BR /&gt;&lt;BR /&gt;2)      Your comment: The data step shown results in values of "INSULIN" not "INSULIN ASPA".&lt;BR /&gt;&lt;BR /&gt;      My response: You're correct! Sorry, I could not determine why the wide data set does show "INSULIN" instead of "INSULIN ASPA" for DUPERSID 2320222101.&lt;BR /&gt;&lt;BR /&gt;3)      Your question/comment: Also what will you do with the resulting data set? Typically a wide set is much harder to work with.&lt;BR /&gt;&lt;BR /&gt;      My response: I want to count the number of prescription fills/refills at the respondent level and merge this wide data with other person-level data files.&lt;BR /&gt;&lt;BR /&gt;4)      Your question/comment: Can you show exactly what you expect for output? You have so many repeated values in that example data I'm not sure that I understand what is needed or the utility of that many repeated values on an observation.&lt;BR /&gt;&lt;BR /&gt;      My response: The input and output data (desired)  are shown below.&lt;BR /&gt;&lt;BR /&gt;      Input data (one DYPERSID repeated twice)&lt;BR /&gt;      DUPERSID     RXNDC     RXNAME1&lt;BR /&gt;      2320018102     -15     ANTICOAGULANTS&lt;BR /&gt;      2320018102     -15     ANTICOAGULANTS&lt;BR /&gt;&lt;BR /&gt;      Desired output data&lt;BR /&gt;      DUPERSID   RXNDC_RX1   RXNAME_RX1         RXNDC_RX2   RXNAME_RX2&lt;BR /&gt;      2320018102   -15       ANTICOAGULANTS      -15        ANTICOAGULANTS&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;</description>
      <pubDate>Thu, 28 Mar 2024 16:18:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-transpose-ID-value-occurs-twice-in-same-BY-group/m-p/922144#M363138</guid>
      <dc:creator>pkm_edu</dc:creator>
      <dc:date>2024-03-28T16:18:57Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose ID value occurs twice in same BY group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose-ID-value-occurs-twice-in-same-BY-group/m-p/922145#M363139</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/285909"&gt;@pkm_edu&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;1) Sorry for not starting a new thread. Do you want me to create a new thread?&lt;BR /&gt;&lt;BR /&gt;3) Your question/comment: Also what will you do with the resulting data set? Typically a wide set is much harder to work with.&lt;BR /&gt;&lt;BR /&gt;My response: I want to count the number of prescription fills/refills at the respondent level and merge this wide data with other person-level data files.&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes start a new thread, and your question appears to be a "how to count".&lt;/P&gt;
&lt;P&gt;Do you need a data set with the count or a report that you can read. Very likely Proc Freq will handle either.&lt;/P&gt;
&lt;P&gt;Consider if you want a count by person of each of your two variables this may be a start:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Proc freq data=work.testdata;
  /* person with separate table counts of rxndc and rxname*/
   tables dupersid*(rxndc rxname) / norow nocol nopercent;
 /* or count of both at one time*/
   tables dupersid * rxndc * rxname/ list nopercent;
run;&lt;/PRE&gt;
&lt;P&gt;You can create output data sets of either type to merge back on to your other data by Dupersid.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2024 16:33:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-transpose-ID-value-occurs-twice-in-same-BY-group/m-p/922145#M363139</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-03-28T16:33:52Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose ID value occurs twice in same BY group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose-ID-value-occurs-twice-in-same-BY-group/m-p/922220#M363155</link>
      <description>Thank you for your PROC FREQ data aggregation solution (Method 1 SAS code below).&lt;BR /&gt;I have also provided two additional solutions using PROC SUMMARY and PROC SQL (Methods 2 and 3 SAS code below).&lt;BR /&gt;&lt;BR /&gt;Below is the SAS Output for aggregated data.&lt;BR /&gt;&lt;BR /&gt;DUPERSID    RXNDC        RXNAME                                                 count&lt;BR /&gt;ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ&lt;BR /&gt;2320018102  -15          ANTICOAGULANTS                                             2&lt;BR /&gt;2320038101  -15          ANTICOAGULANTS                                             3&lt;BR /&gt;2320105101  -15          INSULIN                                                    4&lt;BR /&gt;2320222101  73070010011  INSULIN ASPA                                               8&lt;BR /&gt;&lt;BR /&gt;Question: What DATA step code would I write to create the output data set (e.g., example observation below) based on the above data set as input? Any hints (or references) would be appreciated.&lt;BR /&gt;&lt;BR /&gt;DUPERSID    RXNDC RXNAME        count  RXNDC1 RXNAME2     RXNDC1 RXNAME2&lt;BR /&gt;&lt;BR /&gt;ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ&lt;BR /&gt;2320018102  -15   ANTICOAGULANTS  2    -15 ANTICOAGULANTS -15 ANTICOAGULANTS&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;********************************************************************&lt;BR /&gt;data testdata;&lt;BR /&gt;infile datalines truncover ;&lt;BR /&gt;input DUPERSID :$10.    RXNDC  :$char11.   RXNAME  &amp;amp; $50.;&lt;BR /&gt;datalines;&lt;BR /&gt;2320018102     -15     ANTICOAGULANTS&lt;BR /&gt;2320018102     -15     ANTICOAGULANTS&lt;BR /&gt;2320038101     -15     ANTICOAGULANTS&lt;BR /&gt;2320038101     -15     ANTICOAGULANTS&lt;BR /&gt;2320038101     -15     ANTICOAGULANTS&lt;BR /&gt;2320105101     -15     INSULIN&lt;BR /&gt;2320105101     -15     INSULIN&lt;BR /&gt;2320105101     -15     INSULIN&lt;BR /&gt;2320105101     -15     INSULIN&lt;BR /&gt;2320222101    73070010011    INSULIN ASPA&lt;BR /&gt;2320222101    73070010011    INSULIN ASPA&lt;BR /&gt;2320222101    73070010011    INSULIN ASPA&lt;BR /&gt;2320222101    73070010011    INSULIN ASPA&lt;BR /&gt;2320222101    73070010011    INSULIN ASPA&lt;BR /&gt;2320222101    73070010011    INSULIN ASPA&lt;BR /&gt;2320222101    73070010011    INSULIN ASPA&lt;BR /&gt;2320222101    73070010011    INSULIN ASPA&lt;BR /&gt;;&lt;BR /&gt;proc print data=testdata; run;&lt;BR /&gt;&lt;BR /&gt;title 'Method 1';&lt;BR /&gt;Proc freq data=work.testdata noprint;&lt;BR /&gt;    tables dupersid * rxndc * rxname / list nopercent out=FreqCount (drop=percent);&lt;BR /&gt;run;&lt;BR /&gt;proc print data=work.FreqCount;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;title 'Method 2';&lt;BR /&gt;proc summary data=testdata nway ;&lt;BR /&gt;  by dupersid rxndc rxname;&lt;BR /&gt; output out=want (rename=(_freq_=count)drop=_type_) ;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=work.want;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;title 'Method 3';&lt;BR /&gt;proc sql;&lt;BR /&gt;  select dupersid, rxndc, rxname, count(*) as count&lt;BR /&gt;    from testdata&lt;BR /&gt;    group by dupersid, rxndc, rxname;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 28 Mar 2024 23:21:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-transpose-ID-value-occurs-twice-in-same-BY-group/m-p/922220#M363155</guid>
      <dc:creator>pkm_edu</dc:creator>
      <dc:date>2024-03-28T23:21:57Z</dc:date>
    </item>
  </channel>
</rss>

