<?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 Question about trannsposing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Question-about-trannsposing/m-p/536573#M147463</link>
    <description>&lt;P&gt;I am not sure why I find TRANSPOSE hard to learn but I do.&amp;nbsp; In any case, now I have this data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input cat1_s1_Andrew cat1_s2_Andrew cat2_s1_Andrew cat2_s2_Andrew cat3_s1_Andrew cat3_s2_Andrew cat4_s1_Andrew cat4_s2_Andrew cat4_s2_Mikhail cat1_s1_Mikhail cat1_s2_Mikhail cat2_s1_Mikhail cat2_s2_Mikhail cat3_s1_Mikhail cat3_s2_Mikhail cat4_s1_Mikhail horiz vert;
  datalines;
   0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 
   0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 
   0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 1
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but with about 1700 rows and not all 0's.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I would like is a data set with these variables:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;cat (from 1 to 4, taken from the suffix to cat&lt;/LI&gt;&lt;LI&gt;s (1 or 2, from the suffix to s)&lt;/LI&gt;&lt;LI&gt;Name (Andrew or Mikhail)&lt;/LI&gt;&lt;LI&gt;Horiz&lt;/LI&gt;&lt;LI&gt;Vert&lt;/LI&gt;&lt;LI&gt;The value (mostly 0's, above, but not in my full data set)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I am using SAS 9.4 on Windows 10&lt;/P&gt;</description>
    <pubDate>Mon, 18 Feb 2019 20:48:56 GMT</pubDate>
    <dc:creator>plf515</dc:creator>
    <dc:date>2019-02-18T20:48:56Z</dc:date>
    <item>
      <title>Question about trannsposing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-trannsposing/m-p/536573#M147463</link>
      <description>&lt;P&gt;I am not sure why I find TRANSPOSE hard to learn but I do.&amp;nbsp; In any case, now I have this data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input cat1_s1_Andrew cat1_s2_Andrew cat2_s1_Andrew cat2_s2_Andrew cat3_s1_Andrew cat3_s2_Andrew cat4_s1_Andrew cat4_s2_Andrew cat4_s2_Mikhail cat1_s1_Mikhail cat1_s2_Mikhail cat2_s1_Mikhail cat2_s2_Mikhail cat3_s1_Mikhail cat3_s2_Mikhail cat4_s1_Mikhail horiz vert;
  datalines;
   0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 
   0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 
   0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 1
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but with about 1700 rows and not all 0's.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I would like is a data set with these variables:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;cat (from 1 to 4, taken from the suffix to cat&lt;/LI&gt;&lt;LI&gt;s (1 or 2, from the suffix to s)&lt;/LI&gt;&lt;LI&gt;Name (Andrew or Mikhail)&lt;/LI&gt;&lt;LI&gt;Horiz&lt;/LI&gt;&lt;LI&gt;Vert&lt;/LI&gt;&lt;LI&gt;The value (mostly 0's, above, but not in my full data set)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I am using SAS 9.4 on Windows 10&lt;/P&gt;</description>
      <pubDate>Mon, 18 Feb 2019 20:48:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-trannsposing/m-p/536573#M147463</guid>
      <dc:creator>plf515</dc:creator>
      <dc:date>2019-02-18T20:48:56Z</dc:date>
    </item>
    <item>
      <title>Re: Question about trannsposing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-trannsposing/m-p/536584#M147466</link>
      <description>&lt;P&gt;here is a link to proc transpose that have good examples with step by step instructions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Feb 2019 21:16:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-trannsposing/m-p/536584#M147466</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2019-02-18T21:16:20Z</dc:date>
    </item>
    <item>
      <title>Re: Question about trannsposing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-trannsposing/m-p/536587#M147468</link>
      <description>&lt;P&gt;Does your real file have anything to uniquely identify the rows?&lt;/P&gt;</description>
      <pubDate>Mon, 18 Feb 2019 21:33:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-trannsposing/m-p/536587#M147468</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-02-18T21:33:03Z</dc:date>
    </item>
    <item>
      <title>Re: Question about trannsposing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-trannsposing/m-p/536588#M147469</link>
      <description>&lt;P&gt;Do you only have the SAS dataset?&lt;/P&gt;
&lt;P&gt;Or do you have a raw text file like your example data?&lt;/P&gt;
&lt;P&gt;It is trivial to read the raw data directly if you have it.&amp;nbsp; (Well not so trivial with HORIZ and VERT at the END of the line instead of the BEGINNING).&lt;/P&gt;</description>
      <pubDate>Mon, 18 Feb 2019 21:35:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-trannsposing/m-p/536588#M147469</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-02-18T21:35:00Z</dc:date>
    </item>
    <item>
      <title>Re: Question about trannsposing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-trannsposing/m-p/536591#M147470</link>
      <description>&lt;P&gt;It started as a .csv file, but I had to create horiz and vert from another variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code for reading it and creating what I have is&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname jeff "C:\personal\Consults\Jeff Sterk";

PROC IMPORT OUT= jeff.sixteen 
            DATAFILE= "C:\personal\Consults\Jeff Sterk\Unsorted16.csv" 
            DBMS=CSV REPLACE;
     GETNAMES=YES;
     DATAROW=2; 
RUN;


data jeff.sixteen;
 set jeff.sixteen;
 horiz = mod(location-1, 27);
 vert = int(location/27) + 1;
 drop location;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Feb 2019 21:41:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-trannsposing/m-p/536591#M147470</guid>
      <dc:creator>plf515</dc:creator>
      <dc:date>2019-02-18T21:41:06Z</dc:date>
    </item>
    <item>
      <title>Re: Question about trannsposing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-trannsposing/m-p/536592#M147471</link>
      <description>&lt;P&gt;No, but it would be easy enough to add an ID either in a DATA STEP or in the .csv file where this started.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Feb 2019 21:42:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-trannsposing/m-p/536592#M147471</guid>
      <dc:creator>plf515</dc:creator>
      <dc:date>2019-02-18T21:42:42Z</dc:date>
    </item>
    <item>
      <title>Re: Question about trannsposing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-trannsposing/m-p/536595#M147473</link>
      <description>&lt;P&gt;You could use an array instead of PROC TRANSPOSE:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(keep=cat s name horiz vert value);
length cat s 8 name $7;
set have;
array v cat1_s1_Andrew--cat4_s2_Andrew cat1_s1_Mikhail--cat4_s1_Mikhail cat4_s2_Mikhail;
do over v;
  cat=input(char(vname(v),4),1.);
  s=input(char(vname(v),7),1.);
  name=substr(vname(v),9);
  value=v;
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Feb 2019 21:54:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-trannsposing/m-p/536595#M147473</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-02-18T21:54:49Z</dc:date>
    </item>
    <item>
      <title>Re: Question about trannsposing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-about-trannsposing/m-p/536596#M147474</link>
      <description>&lt;P&gt;Don't use PROC IMPORT to read simple text files.&amp;nbsp; It just has to make (uneducated) guesses about what is in the data.&lt;/P&gt;
&lt;P&gt;So if you know the order of the columns then just read the values in that order.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  *infile "C:\personal\Consults\Jeff Sterk\Unsorted16.csv"  dsd truncover firstobs=2;
  length Location vert horiz 8 cat 8 s 8 Name $20 ;
  input location @;
  horiz = mod(location-1, 27);
  vert = int(location/27) + 1;
  do name='Andrew','Mikhail';
    do cat=1 to 4;
      do s=1 to 2 ;
        input value @;
        output;
      end;
    end;
  end;
  datalines;
 1  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 
 2  21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 
 3  41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    Location    vert    horiz    cat    s     Name      value

  1        1         1       0       1     1    Andrew        1
  2        1         1       0       1     2    Andrew        2
  3        1         1       0       2     1    Andrew        3
  4        1         1       0       2     2    Andrew        4
  5        1         1       0       3     1    Andrew        5
  6        1         1       0       3     2    Andrew        6
  7        1         1       0       4     1    Andrew        7
  8        1         1       0       4     2    Andrew        8
  9        1         1       0       1     1    Mikhail       9
 10        1         1       0       1     2    Mikhail      10
 11        1         1       0       2     1    Mikhail      11
 12        1         1       0       2     2    Mikhail      12
 13        1         1       0       3     1    Mikhail      13
 14        1         1       0       3     2    Mikhail      14
 15        1         1       0       4     1    Mikhail      15
 16        1         1       0       4     2    Mikhail      16
 17        2         1       1       1     1    Andrew       21
 18        2         1       1       1     2    Andrew       22
 19        2         1       1       2     1    Andrew       23
 20        2         1       1       2     2    Andrew       24
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Feb 2019 21:55:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-about-trannsposing/m-p/536596#M147474</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-02-18T21:55:12Z</dc:date>
    </item>
  </channel>
</rss>

