<?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 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE/m-p/473744#M121603</link>
    <description>&lt;P&gt;I post as well the proc sql alternative to your array solution:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  set test;
  ord=input(compress(_name_,,"kd"),best.);
run;

proc sort data=test;
  by modelo name_stat ord concept;
run;

proc sql;
create table work.test3 as
select modelo, name_stat, ord,
sum (case when concept = "lc" then value else 0 end) as lc format percent9.2,
sum (case when concept = "t" then value else 0 end) as t format percent9.2, 
sum (case when concept = "pet_comm_" then value else 0 end) as pet_comm_ format percent9.2
from test
group by modelo, name_stat, ord;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Jun 2018 14:12:06 GMT</pubDate>
    <dc:creator>acordes</dc:creator>
    <dc:date>2018-06-27T14:12:06Z</dc:date>
    <item>
      <title>PROC TRANSPOSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE/m-p/473695#M121586</link>
      <description>&lt;P&gt;I thought I would control PROC TRANSPOSE well, but I'm having a problem with it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having NLEVELS=3 for the variable concept I would like to have create 3 columns LC, T and PET_COMM_ with the variable value.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But when executing the code I end up getting the error message&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: The ID value "LC" occurs twice in el mismo grupo BY.&lt;BR /&gt;ERROR: The ID value "LC" occurs twice in el mismo grupo BY.&lt;BR /&gt;ERROR: The ID value "LC" occurs twice in el mismo grupo BY.&lt;BR /&gt;ERROR: The ID value "LC" occurs twice in el mismo grupo BY.&lt;BR /&gt;ERROR: The ID value "PET_COMM_" occurs twice in el mismo grupo BY.&lt;BR /&gt;ERROR: The ID value "PET_COMM_" occurs twice in el mismo grupo BY.&lt;BR /&gt;ERROR: The ID value "PET_COMM_" occurs twice in el mismo grupo BY.&lt;BR /&gt;ERROR: The ID value "PET_COMM_" occurs twice in el mismo grupo BY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.TEST;
  infile datalines dsd truncover;
  input MODELO:$21. NAME_STAT:$33. _NAME_:$14. VALUE:32. CONCEPT:$30.;
datalines4;
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,LC12,-0.005,LC
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,LC24,-0.01,LC
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,LC36,-0.015,LC
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,LC48,-0.02,LC
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,LC60,-0.02,LC
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,T12,-0.005,T
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,T24,-0.01,T
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,T36,-0.015,T
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,T48,-0.02,T
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,T60,-0.02,T
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,PET_COMM_12,0.5642043742,PET_COMM_
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,PET_COMM_24,0.5041646406,PET_COMM_
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,PET_COMM_36,0.4441249367,PET_COMM_
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,PET_COMM_48,0.3840852925,PET_COMM_
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,PET_COMM_60,0.3290455588,PET_COMM_
ODUMMYA FL 2017,ODUMMYA DIESEL,LC12,-0.005,LC
ODUMMYA FL 2017,ODUMMYA DIESEL,LC24,-0.01,LC
ODUMMYA FL 2017,ODUMMYA DIESEL,LC36,-0.015,LC
ODUMMYA FL 2017,ODUMMYA DIESEL,LC48,-0.02,LC
ODUMMYA FL 2017,ODUMMYA DIESEL,LC60,-0.02,LC
ODUMMYA FL 2017,ODUMMYA DIESEL,T12,-0.005,T
ODUMMYA FL 2017,ODUMMYA DIESEL,T24,-0.01,T
ODUMMYA FL 2017,ODUMMYA DIESEL,T36,-0.015,T
ODUMMYA FL 2017,ODUMMYA DIESEL,T48,-0.02,T
ODUMMYA FL 2017,ODUMMYA DIESEL,T60,-0.02,T
ODUMMYA FL 2017,ODUMMYA DIESEL,PET_COMM_12,0.5853021073,PET_COMM_
ODUMMYA FL 2017,ODUMMYA DIESEL,PET_COMM_24,0.5252623736,PET_COMM_
ODUMMYA FL 2017,ODUMMYA DIESEL,PET_COMM_36,0.4652226698,PET_COMM_
ODUMMYA FL 2017,ODUMMYA DIESEL,PET_COMM_48,0.4051830255,PET_COMM_
ODUMMYA FL 2017,ODUMMYA DIESEL,PET_COMM_60,0.3501432919,PET_COMM_
;;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SORT DATA=WORK.TEST;
BY MODELO NAME_STAT CONCEPT;
RUN;

PROC TRANSPOSE DATA=WORK.TEST(DROP=_NAME_);
BY MODELO NAME_STAT;
VAR VALUE;
ID CONCEPT;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Jun 2018 12:37:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE/m-p/473695#M121586</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2018-06-27T12:37:17Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TRANSPOSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE/m-p/473700#M121587</link>
      <description>&lt;P&gt;Look at the data you posted:&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,LC12,-0.005,LC ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,LC24,-0.01,LC ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,LC36,-0.015,LC ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,LC48,-0.02,LC ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,LC60,-0.02,LC&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;You are transposing this data by&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;&lt;SPAN class="token statement"&gt;BY&lt;/SPAN&gt; MODELO NAME_STAT&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/LI-CODE&gt;
&lt;P&gt;As we can see modelo + name_stat has five records all with the same LC result.&amp;nbsp; SAS cannot transpose that.&amp;nbsp; You have not provided a want output so its hard to say, but perhaps a datastep before which adds an incremental number to the LC column so each are distinct would solve it:&lt;/P&gt;
&lt;PRE&gt;data test;
  set test;
  by modelo name_stat concept;
  retain c;
  c=ifn(first.concept,1,c+1);
  concept=cats(concept,put(c,best.));
run;&lt;/PRE&gt;
&lt;P&gt;Put that after your sort.&lt;/P&gt;
&lt;P&gt;And please stop CODING ALL IN UPPERCASE!&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 12:48:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE/m-p/473700#M121587</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-06-27T12:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TRANSPOSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE/m-p/473711#M121589</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is it an unwritten rule that&amp;nbsp; coding in UPPERCASE is a NO GO?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to have this output:&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="WANT.jpg" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21438iC6F8613753D5F95F/image-size/large?v=v2&amp;amp;px=999" role="button" title="WANT.jpg" alt="WANT.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 13:05:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE/m-p/473711#M121589</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2018-06-27T13:05:02Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TRANSPOSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE/m-p/473722#M121593</link>
      <description>&lt;P&gt;If your data are already in the order shown in your example, then you could use something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data need;
  set test;
  by modelo name_stat concept notsorted;
  if first.concept then order=1;
  else order+1;
run;

PROC SORT DATA=need;
  BY MODELO NAME_STAT order;
RUN;

PROC TRANSPOSE DATA=WORK.need out=want(DROP=_NAME_ order);
  BY MODELO NAME_STAT order;
  VAR VALUE;
  ID CONCEPT;
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 13:34:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE/m-p/473722#M121593</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-06-27T13:34:23Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TRANSPOSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE/m-p/473730#M121596</link>
      <description>&lt;P&gt;Not its not a rule, just good practice, like indenting lines within blocks, finishing macro variables with a point, ending blocks with run; etc.&amp;nbsp; If I wrote my posts back in uppercase people would think I was rudely shouting at them.&amp;nbsp; For your requirement, what I would suggest is an array and by group - you could do it in three transposes, and then merge together, but one datastep will suffice:&lt;/P&gt;
&lt;PRE&gt;data WORK.TEST;
  infile datalines dsd truncover;
  input modelo:$21. name_stat:$33. _name_:$14. value:32. concept:$30.;
datalines;
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,LC12,-0.005,LC
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,LC24,-0.01,LC
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,LC36,-0.015,LC
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,LC48,-0.02,LC
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,LC60,-0.02,LC
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,T12,-0.005,T
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,T24,-0.01,T
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,T36,-0.015,T
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,T48,-0.02,T
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,T60,-0.02,T
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,PET_COMM_12,0.5642043742,PET_COMM_
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,PET_COMM_24,0.5041646406,PET_COMM_
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,PET_COMM_36,0.4441249367,PET_COMM_
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,PET_COMM_48,0.3840852925,PET_COMM_
ODUMMYA COMBI FL 2017,ODUMMYA COMBI DIESEL,PET_COMM_60,0.3290455588,PET_COMM_
ODUMMYA FL 2017,ODUMMYA DIESEL,LC12,-0.005,LC
ODUMMYA FL 2017,ODUMMYA DIESEL,LC24,-0.01,LC
ODUMMYA FL 2017,ODUMMYA DIESEL,LC36,-0.015,LC
ODUMMYA FL 2017,ODUMMYA DIESEL,LC48,-0.02,LC
ODUMMYA FL 2017,ODUMMYA DIESEL,LC60,-0.02,LC
ODUMMYA FL 2017,ODUMMYA DIESEL,T12,-0.005,T
ODUMMYA FL 2017,ODUMMYA DIESEL,T24,-0.01,T
ODUMMYA FL 2017,ODUMMYA DIESEL,T36,-0.015,T
ODUMMYA FL 2017,ODUMMYA DIESEL,T48,-0.02,T
ODUMMYA FL 2017,ODUMMYA DIESEL,T60,-0.02,T
ODUMMYA FL 2017,ODUMMYA DIESEL,PET_COMM_12,0.5853021073,PET_COMM_
ODUMMYA FL 2017,ODUMMYA DIESEL,PET_COMM_24,0.5252623736,PET_COMM_
ODUMMYA FL 2017,ODUMMYA DIESEL,PET_COMM_36,0.4652226698,PET_COMM_
ODUMMYA FL 2017,ODUMMYA DIESEL,PET_COMM_48,0.4051830255,PET_COMM_
ODUMMYA FL 2017,ODUMMYA DIESEL,PET_COMM_60,0.3501432919,PET_COMM_
;
run;

data test;
  set test;
  ord=input(compress(_name_,,"kd"),best.);
run;

proc sort data=test;
  by modelo name_stat ord concept;
run;

data want (keep=modelo name_stat ord lc t pet_comm_);
  set test;
  retain lc t pet_comm_;
  by modelo name_stat ord;
  if first.ord then call missing(lc,t,pet_comm_);
  if concept="LC" then lc=value;
  if concept="T" then t=value;
  if concept="PET_COMM_" then pet_comm_=value;
  if last.ord then output; 
run;
&lt;/PRE&gt;
&lt;P&gt;Do note that I have created a new variable called ord, this is necessary otherwise there is not way of knowing which records should all be on the same line, I assume that LC12, should appear on the same row as T12 for instance.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 13:42:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE/m-p/473730#M121596</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-06-27T13:42:30Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TRANSPOSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE/m-p/473735#M121598</link>
      <description>&lt;P&gt;Awesome. AWESOME &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ok, I understand your code and it's a fine solution.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And regarding the good coding practice I didn't realize that it could be offensive. For my eyes it's cleaner to have all in uppercase.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bye, Arne&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 13:50:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE/m-p/473735#M121598</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2018-06-27T13:50:18Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TRANSPOSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE/m-p/473741#M121600</link>
      <description>&lt;P&gt;I like&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;&amp;nbsp;solution, but instead of assigning order values sequentially use the _NAME_ to get the order values. If there are missing values then assigning sequential numbers might result in different results.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data need;
  set test;
order=substr(_name_,length(_name_)-1,2);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With missing T12 row you get this result with order values from _name_:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 545px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21443iCDF1C9E83AE38030/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If using sequential order then missing value will the at last record.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 558px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21444iB2B52D12706A25B1/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 13:57:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE/m-p/473741#M121600</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-06-27T13:57:19Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TRANSPOSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE/m-p/473743#M121602</link>
      <description>&lt;P&gt;Thanks, very good&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 14:10:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE/m-p/473743#M121602</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2018-06-27T14:10:13Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TRANSPOSE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE/m-p/473744#M121603</link>
      <description>&lt;P&gt;I post as well the proc sql alternative to your array solution:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  set test;
  ord=input(compress(_name_,,"kd"),best.);
run;

proc sort data=test;
  by modelo name_stat ord concept;
run;

proc sql;
create table work.test3 as
select modelo, name_stat, ord,
sum (case when concept = "lc" then value else 0 end) as lc format percent9.2,
sum (case when concept = "t" then value else 0 end) as t format percent9.2, 
sum (case when concept = "pet_comm_" then value else 0 end) as pet_comm_ format percent9.2
from test
group by modelo, name_stat, ord;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 14:12:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-TRANSPOSE/m-p/473744#M121603</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2018-06-27T14:12:06Z</dc:date>
    </item>
  </channel>
</rss>

