<?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 a simple proc transpose, but got stucked there in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/a-simple-proc-transpose-but-got-stucked-there/m-p/694850#M211948</link>
    <description>&lt;P&gt;My data has 1,201,250 rows, part of the data is as below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;In each form, each examinee take the same 250 item.&amp;nbsp; There are a few same itemID across different forms. e.g. item pp012 in both AAA and BBB, pp012 and pp024 in both BBB and CCC.&amp;nbsp; there are 1350 unique items across all forms. I want to transpose this data back to wide to make a SPARSE matrix in terms of raw. The desired SPARSE matrix should have 1350 columns in terms of raw score. SPARSE matrix means there are no data in a certain column after transposing.&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;DATA have ; 
  INPUT form examineeID _NAME_   itemID  raw; 
CARDS ; 
AAA 111 raw_1  pp012   0 
AAA 111 raw_2  pp014   1
AAA 111 raw_3  pp017   1 
AAA 111 raw_4  pp015   0 
..
AAA 444 raw_1  pp012   1 
AAA 444 raw_2  pp014   0 
AAA 444 raw_3  pp017   1 
AAA 444 raw_4  pp015   1
...
BBB 777  raw_1 pp012   0
BBB 777  raw_2 pp024   1
BBB 777  raw_3 pp027   0
BBB 777  raw_4 pp025   1
...
BBB 999  raw_1 pp012   1
BBB 999  raw_2 pp024   1
BBB 999  raw_3 pp027   0
BBB 999  raw_4 pp025   0
....
CCC 666  raw_1 pp012   0
CCC 666  raw_2 pp024   1
CCC 666  raw_3 pp037   0
CCC 666  raw_4 pp035   1
...
CCC 888  raw_1 pp012   1
CCC 888  raw_2 pp024   1
CCC 888  raw_3 pp037   0
CCC 888  raw_4 pp035   0
...
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;I used the following code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have; by examineeid; run;
proc transpose data=have  out=want (drop=_NAME_) delim=_;
  by examineeid;
  id itemid;
  var raw;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The resulted matrix is 4805x1350, which is the correct dimension. But from left to right, the columns SHOULD be in the ascending order of itemID. How can I get that order? I tried to sort "have" data by itemID examineeID before transposing, but the resulted matrix is not the correct dimension I wanted. I am stucked there for a while, much thanks to your help!&lt;/P&gt;</description>
    <pubDate>Wed, 28 Oct 2020 13:32:28 GMT</pubDate>
    <dc:creator>superbug</dc:creator>
    <dc:date>2020-10-28T13:32:28Z</dc:date>
    <item>
      <title>a simple proc transpose, but got stucked there</title>
      <link>https://communities.sas.com/t5/SAS-Programming/a-simple-proc-transpose-but-got-stucked-there/m-p/694850#M211948</link>
      <description>&lt;P&gt;My data has 1,201,250 rows, part of the data is as below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;In each form, each examinee take the same 250 item.&amp;nbsp; There are a few same itemID across different forms. e.g. item pp012 in both AAA and BBB, pp012 and pp024 in both BBB and CCC.&amp;nbsp; there are 1350 unique items across all forms. I want to transpose this data back to wide to make a SPARSE matrix in terms of raw. The desired SPARSE matrix should have 1350 columns in terms of raw score. SPARSE matrix means there are no data in a certain column after transposing.&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;DATA have ; 
  INPUT form examineeID _NAME_   itemID  raw; 
CARDS ; 
AAA 111 raw_1  pp012   0 
AAA 111 raw_2  pp014   1
AAA 111 raw_3  pp017   1 
AAA 111 raw_4  pp015   0 
..
AAA 444 raw_1  pp012   1 
AAA 444 raw_2  pp014   0 
AAA 444 raw_3  pp017   1 
AAA 444 raw_4  pp015   1
...
BBB 777  raw_1 pp012   0
BBB 777  raw_2 pp024   1
BBB 777  raw_3 pp027   0
BBB 777  raw_4 pp025   1
...
BBB 999  raw_1 pp012   1
BBB 999  raw_2 pp024   1
BBB 999  raw_3 pp027   0
BBB 999  raw_4 pp025   0
....
CCC 666  raw_1 pp012   0
CCC 666  raw_2 pp024   1
CCC 666  raw_3 pp037   0
CCC 666  raw_4 pp035   1
...
CCC 888  raw_1 pp012   1
CCC 888  raw_2 pp024   1
CCC 888  raw_3 pp037   0
CCC 888  raw_4 pp035   0
...
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;I used the following code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have; by examineeid; run;
proc transpose data=have  out=want (drop=_NAME_) delim=_;
  by examineeid;
  id itemid;
  var raw;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The resulted matrix is 4805x1350, which is the correct dimension. But from left to right, the columns SHOULD be in the ascending order of itemID. How can I get that order? I tried to sort "have" data by itemID examineeID before transposing, but the resulted matrix is not the correct dimension I wanted. I am stucked there for a while, much thanks to your help!&lt;/P&gt;</description>
      <pubDate>Wed, 28 Oct 2020 13:32:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/a-simple-proc-transpose-but-got-stucked-there/m-p/694850#M211948</guid>
      <dc:creator>superbug</dc:creator>
      <dc:date>2020-10-28T13:32:28Z</dc:date>
    </item>
    <item>
      <title>Re: a simple proc transpose, but got stucked there</title>
      <link>https://communities.sas.com/t5/SAS-Programming/a-simple-proc-transpose-but-got-stucked-there/m-p/694856#M211951</link>
      <description>&lt;P&gt;Please test your data step code before posting, so you can be sure it works and creates valid data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Create a pattern dataset of all items, and prepend that before transposing; filter out the empty observation after the transpose:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
input form $ examineeID $ _NAME_ $ itemID $ raw; 
datalines; 
AAA 111 raw_1  pp012   0 
AAA 111 raw_2  pp014   1
AAA 111 raw_3  pp017   1 
AAA 111 raw_4  pp015   0 
AAA 444 raw_1  pp012   1 
AAA 444 raw_2  pp014   0 
AAA 444 raw_3  pp017   1 
AAA 444 raw_4  pp015   1
BBB 777  raw_1 pp012   0
BBB 777  raw_2 pp024   1
BBB 777  raw_3 pp027   0
BBB 777  raw_4 pp025   1
BBB 999  raw_1 pp012   1
BBB 999  raw_2 pp024   1
BBB 999  raw_3 pp027   0
BBB 999  raw_4 pp025   0
CCC 666  raw_1 pp012   0
CCC 666  raw_2 pp024   1
CCC 666  raw_3 pp037   0
CCC 666  raw_4 pp035   1
CCC 888  raw_1 pp012   1
CCC 888  raw_2 pp024   1
CCC 888  raw_3 pp037   0
CCC 888  raw_4 pp035   0
;

proc sort
  data=have (keep=itemid)
  out=pattern
  nodupkey
;
by itemid;
run;

proc sort data=have;
by examineeid;
run;

data pretrans;
set
  pattern
  have
;
run;

proc transpose
  data=pretrans
  out=want (drop=_NAME_ where=(examineeid ne ""))
  delim=_
;
by examineeid;
id itemid;
var raw;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Oct 2020 13:48:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/a-simple-proc-transpose-but-got-stucked-there/m-p/694856#M211951</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-28T13:48:29Z</dc:date>
    </item>
    <item>
      <title>Re: a simple proc transpose, but got stucked there</title>
      <link>https://communities.sas.com/t5/SAS-Programming/a-simple-proc-transpose-but-got-stucked-there/m-p/694892#M211968</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;THANK YOU SO MUCH!&lt;/P&gt;
&lt;P&gt;A double thumb up to your help!&lt;/P&gt;</description>
      <pubDate>Wed, 28 Oct 2020 14:48:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/a-simple-proc-transpose-but-got-stucked-there/m-p/694892#M211968</guid>
      <dc:creator>superbug</dc:creator>
      <dc:date>2020-10-28T14:48:50Z</dc:date>
    </item>
  </channel>
</rss>

