<?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: transposing multiple variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/transposing-multiple-variables/m-p/281360#M57046</link>
    <description>honestly, i didn't get the idea of the macro with my basic SAS knowledge - maybe in a vew month :-). but thank's for your advice</description>
    <pubDate>Thu, 30 Jun 2016 07:40:26 GMT</pubDate>
    <dc:creator>Sandra_L</dc:creator>
    <dc:date>2016-06-30T07:40:26Z</dc:date>
    <item>
      <title>transposing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transposing-multiple-variables/m-p/281096#M56933</link>
      <description>&lt;P&gt;Hi guys!&lt;/P&gt;&lt;P&gt;here is what i have: &lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/3837iB3B45D0FE357AE45/image-size/original?v=v2&amp;amp;px=-1" alt="bsp.GIF" title="bsp.GIF" border="0" /&gt;&lt;/P&gt;&lt;P&gt;and what i want: &lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/3838i1E96B63B4AACE52D/image-size/original?v=v2&amp;amp;px=-1" alt="bsp2.GIF" title="bsp2.GIF" border="0" /&gt;&lt;/P&gt;&lt;P&gt;i tried array and simle transponse with by and var but never got the right structure.&lt;/P&gt;&lt;P&gt;any ideas?&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2016 13:25:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transposing-multiple-variables/m-p/281096#M56933</guid>
      <dc:creator>Sandra_L</dc:creator>
      <dc:date>2016-06-29T13:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: transposing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transposing-multiple-variables/m-p/281105#M56935</link>
      <description>&lt;P&gt;You'll need two transposes and a merge:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input pronum hor_nr horiz $ humus $;
cards;
203 1 Cv h4
203 2 Cv h2
205 1 Cv h0
205 2 Ah h3
205 3 Yro h0
;
run;

proc transpose data=have prefix=horiz out=want1;
by pronum;
id hor_nr;
var horiz;
run;

proc transpose data=have prefix=humus out=want2;
by pronum;
id hor_nr;
var humus;
run;

data want;
merge
  want1
  want2
;
by pronum;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Jun 2016 13:44:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transposing-multiple-variables/m-p/281105#M56935</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-06-29T13:44:15Z</dc:date>
    </item>
    <item>
      <title>Re: transposing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transposing-multiple-variables/m-p/281106#M56936</link>
      <description>&lt;P&gt;&lt;A href="http://www.sascommunity.org/wiki/A_Better_Way_to_Flip_(Transpose)_a_SAS_Dataset" target="_blank"&gt;http://www.sascommunity.org/wiki/A_Better_Way_to_Flip_(Transpose)_a_SAS_Dataset&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;This macro works well.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2016 13:45:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transposing-multiple-variables/m-p/281106#M56936</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-29T13:45:38Z</dc:date>
    </item>
    <item>
      <title>Re: transposing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transposing-multiple-variables/m-p/281107#M56937</link>
      <description>&lt;P&gt;hey, thanks. i could merge, but i habe 20 variables and i was looking for a smoother way without having to produce 20 new sets...&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2016 13:49:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transposing-multiple-variables/m-p/281107#M56937</guid>
      <dc:creator>Sandra_L</dc:creator>
      <dc:date>2016-06-29T13:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: transposing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transposing-multiple-variables/m-p/281129#M56946</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;Will you go on to use &amp;nbsp;hor_nr1, hor_nr2, hor_nr3 etc variables from the final dataset? I suspect not, in which case two proc transpose and a data step can be used, and will expand to as many variables as you want (by listing them in the var statement of the first proc transpose).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input pronum hor_nr horiz $ humus $;&lt;BR /&gt;cards;&lt;BR /&gt;203 1 Cv h4&lt;BR /&gt;203 2 Cv h2&lt;BR /&gt;205 1 Cv h0&lt;BR /&gt;205 2 Ah h3&lt;BR /&gt;205 3 Yro h0&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc transpose data=have out=dat1;&lt;BR /&gt;var horiz humus;&lt;BR /&gt;by pronum hor_nr;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data dat1;&lt;BR /&gt;set dat1;&lt;BR /&gt;varnam=cats(_name_,hor_nr);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc transpose data=dat1 out=want;&lt;BR /&gt;by pronum;&lt;BR /&gt;id varnam;&lt;BR /&gt;var col1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(I've edited to fix an error in my first post)&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2016 15:39:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transposing-multiple-variables/m-p/281129#M56946</guid>
      <dc:creator>JohnHoughton</dc:creator>
      <dc:date>2016-06-29T15:39:29Z</dc:date>
    </item>
    <item>
      <title>Re: transposing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transposing-multiple-variables/m-p/281136#M56950</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;HAVE                                                                                                                                                            
                                                                                                                                                                
data have;                                                                                                                                                      
input pronum hor_nr horiz $ humus $;                                                                                                                            
cards;                                                                                                                                                          
203 1 Cv h4                                                                                                                                                     
203 2 Cv h2                                                                                                                                                     
205 1 Cv h0                                                                                                                                                     
205 2 Ah h3                                                                                                                                                     
205 3 Yro h0                                                                                                                                                    
;                                                                                                                                                               
run;                                                                                                                                                            
                                                                                                                                                                
Up to 40 obs WORK.HAVE total obs=5                                                                                                                              
                                                                                                                                                                
Obs    PRONUM    HOR_NR    HORIZ    HUMUS                                                                                                                       
                                                                                                                                                                
 1       203        1       Cv       h4                                                                                                                         
 2       203        2       Cv       h2                                                                                                                         
 3       205        1       Cv       h0                                                                                                                         
 4       205        2       Ah       h3                                                                                                                         
 5       205        3       Yro      h0                                                                                                                         
                                                                                                                                                                
WANT                                                                                                                                                            
                                                                                                                                                                
                                                                                                                                                                
Up to 40 obs WORK.WANT total obs=2                                                                                                                              
                                                                                                                                                                
Obs    PRONUM    _NAME_    HORIZ1    HORIZ2    HORIZ3    HUMUS1    HUMUS2    HUMUS3                                                                             
                                                                                                                                                                
 1       203     HUMUS       Cv        Cv                  h4        h2                                                                                         
 2       205     HUMUS       Cv        Ah       Yro        h0        h3        h0                                                                               
                                                                                                                                                                
                                                                                                                                                                
COUPLE OF SOLUTIONS                                                                                                                                              
                                                                                                                                                                
SOLUTION 1 - NORMALIZE (LONG AND SKINNY)                                                                                                                        
                                                                                                                                                                
data have;                                                                                                                                                      
input pronum hor_nr horiz $ humus $;                                                                                                                            
nam='HORIZ';val=HORIZ;output;                                                                                                                                   
nam='HUMUS';val=HUMUS;output;                                                                                                                                   
drop horiz humus;                                                                                                                                               
cards;                                                                                                                                                          
203 1 Cv h4                                                                                                                                                     
203 2 Cv h2                                                                                                                                                     
205 1 Cv h0                                                                                                                                                     
205 2 Ah h3                                                                                                                                                     
205 3 Yro h0                                                                                                                                                    
;                                                                                                                                                               
run;                                                                                                                                                            
                                                                                                                                                                
                                                                                                                                                                
/*                                                                                                                                                              
Up to 40 obs WORK.HAVE total obs=10                                                                                                                             
                                                                                                                                                                
Obs    PRONUM    HOR_NR     NAM     VAL                                                                                                                         
                                                                                                                                                                
  1      203        1      HORIZ    Cv                                                                                                                          
  2      203        1      HUMUS    h4                                                                                                                          
  3      203        2      HORIZ    Cv                                                                                                                          
  4      203        2      HUMUS    h2                                                                                                                          
  5      205        1      HORIZ    Cv                                                                                                                          
  6      205        1      HUMUS    h0                                                                                                                          
  7      205        2      HORIZ    Ah                                                                                                                          
  8      205        2      HUMUS    h3                                                                                                                          
  9      205        3      HORIZ    Yro                                                                                                                         
 10      205        3      HUMUS    h0                                                                                                                          
*/                                                                                                                                                              
                                                                                                                                                                
proc transpose data=have out=havxpo;                                                                                                                            
by pronum;                                                                                                                                                      
id nam hor_nr;                                                                                                                                                  
var val;                                                                                                                                                        
;run;quit;                                                                                                                                                      
                                                                                                                                                                
                                                                                                                                                                
Up to 40 obs WORK.HAVXPO total obs=2                                                                                                                            
                                                                                                                                                                
Obs    PRONUM    _NAME_    HORIZ1    HUMUS1    HORIZ2    HUMUS2    HORIZ3    HUMUS3                                                                             
                                                                                                                                                                
 1       203      VAL        Cv        h4        Cv        h2                                                                                                   
 2       205      VAL        Cv        h0        Ah        h3       Yro        h0                                                                               
                                                                                                                                                                
USE ARRAYS   &lt;BR /&gt;                                                                                                                                                             
* note separated strips leading blanks;                                                                                                                         
* need to now the max dimension of (horix and humus);                                                                                                           
proc sql;select max(hor_nr) into :dim separated by'' from have;                                                                                                 
                                                                                                                                                                
                                                                                                                                                                
--------                                                                                                                                                        
       3                                                                                                                                                        
                                                                                                                                                                
                                                                                                                                                                
data havary;                                                                                                                                                    
  retain pronum horz1-horz&amp;amp;dim. hums1-hums&amp;amp;dim.;                                                                                                                
  set have;                                                                                                                                                     
  by pronum;                                                                                                                                                    
  array horizs[&amp;amp;dim.] $8 horz1-horz&amp;amp;dim.;                                                                                                                       
  array humuss[&amp;amp;dim.] $8 hums1-hums&amp;amp;dim.;                                                                                                                       
  horizs[ hor_nr]=horiz;                                                                                                                                        
  humuss[ hor_nr]=humus;                                                                                                                                        
  if last.pronum then output;                                                                                                                                   
  keep pronum hor_nr horz: hums:;                                                                                                                               
;run;quit;                                                                                                                                                      
                                                                                                                                                                
                                                                                                                                                                
Up to 40 obs WORK.HAVARY total obs=2                                                                                                                            
                                                                                                                                                                
Obs    PRONUM    HORZ1    HORZ2    HORZ3    HUMS1    HUMS2    HUMS3    HOR_NR                                                                                   
                                                                                                                                                                
 1       203      Cv       Cv                h4       h2                  2                                                                                     
 2       205      Cv       Ah       Yro      h0       h3       h0         3                                                                                     
                                                                                                                                                                
                          &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2016 15:23:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transposing-multiple-variables/m-p/281136#M56950</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2016-06-29T15:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: transposing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transposing-multiple-variables/m-p/281149#M56955</link>
      <description>&lt;P&gt;&amp;nbsp;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;I realised you can have a variable in the by statement and in the var statement of proc transpose.&lt;/P&gt;&lt;P&gt;So by adding the hor_nr variable in the var statement , the output looks like your original (i.e includes hor_nr1, hor_nr2 etc)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input pronum hor_nr horiz $ humus $;&lt;BR /&gt;cards;&lt;BR /&gt;203 1 Cv h4&lt;BR /&gt;203 2 Cv h2&lt;BR /&gt;205 1 Cv h0&lt;BR /&gt;205 2 Ah h3&lt;BR /&gt;205 3 Yro h0&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc transpose data=have out=dat1;&lt;BR /&gt;var &lt;STRONG&gt;hor_nr&lt;/STRONG&gt; horiz humus;&lt;BR /&gt;by pronum hor_nr;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data dat1;&lt;BR /&gt;set dat1;&lt;BR /&gt;varnam=cats(_name_,hor_nr);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc transpose data=dat1 out=want;&lt;BR /&gt;by pronum;&lt;BR /&gt;id varnam;&lt;BR /&gt;var col1;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2016 15:53:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transposing-multiple-variables/m-p/281149#M56955</guid>
      <dc:creator>JohnHoughton</dc:creator>
      <dc:date>2016-06-29T15:53:35Z</dc:date>
    </item>
    <item>
      <title>Re: transposing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transposing-multiple-variables/m-p/281168#M56962</link>
      <description>&lt;P&gt;Sandra,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Assuming that you do want the exact result you specified in your request, using the %transpose macro that Fareeza suggested with the follow command will give you a result that is identical to your example output. The only thing you would have to change is to add your other 17 variables in the var parameter. However, that can also be a varlist so it could be as simple as something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;var hor_nr--whatever_the_last_variable_name_is&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%transpose(data=have, out=want, by=pronum, id=hor_nr,&amp;nbsp;var=hor_nr horiz humus)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Art&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2016 17:06:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transposing-multiple-variables/m-p/281168#M56962</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2016-06-29T17:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: transposing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transposing-multiple-variables/m-p/281341#M57038</link>
      <description>&lt;P&gt;It is easy for proc means + idgroup .&lt;/P&gt;
&lt;P&gt;If you have big table try MERGE skill proposed by me ,Arthur.T , Matt :&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings15/2785-2015.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings15/2785-2015.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input pronum hor_nr horiz $ humus $;
cards;
203 1 Cv h4
203 2 Cv h2
205 1 Cv h0
205 2 Ah h3
205 3 Yro h0
;
run;
proc sql noprint;
 select max(n) into : n
  from (select count(*) as n from have group by pronum);
quit;
proc summary data=have;
by pronum ;
output out=want(drop=_type_ _freq_) idgroup(out[&amp;amp;n] ( hor_nr horiz  humus)=);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Jun 2016 05:40:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transposing-multiple-variables/m-p/281341#M57038</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-06-30T05:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: transposing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transposing-multiple-variables/m-p/281360#M57046</link>
      <description>honestly, i didn't get the idea of the macro with my basic SAS knowledge - maybe in a vew month :-). but thank's for your advice</description>
      <pubDate>Thu, 30 Jun 2016 07:40:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transposing-multiple-variables/m-p/281360#M57046</guid>
      <dc:creator>Sandra_L</dc:creator>
      <dc:date>2016-06-30T07:40:26Z</dc:date>
    </item>
    <item>
      <title>Re: transposing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transposing-multiple-variables/m-p/281361#M57047</link>
      <description>greaty, great! thank you verry much. this seems to me - as SAS beginner - the easiest way.</description>
      <pubDate>Thu, 30 Jun 2016 07:42:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transposing-multiple-variables/m-p/281361#M57047</guid>
      <dc:creator>Sandra_L</dc:creator>
      <dc:date>2016-06-30T07:42:23Z</dc:date>
    </item>
    <item>
      <title>Re: transposing multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transposing-multiple-variables/m-p/281421#M57071</link>
      <description>&lt;P&gt;I agree that learning all of the language elements, in's and out's of macro programming isn't for beginners, but using an already written macro is a totally different thing. Surprise yourself! Try these two steps:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. copy (highlight then ctrl-c) the code at&amp;nbsp;&lt;A href="http://www.sascommunity.org/mwiki/images/b/be/BB-07-2013.sas" target="_blank"&gt;http://www.sascommunity.org/mwiki/images/b/be/BB-07-2013.sas&lt;/A&gt;&lt;/P&gt;&lt;P&gt;2. paste (ctrl-v) the code in whatever window you would normally write your own code&lt;/P&gt;&lt;P&gt;3. run the code&lt;/P&gt;&lt;P&gt;4. then run the following:&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;                                                                                                                                                      
&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; pronum hor_nr horiz &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt; humus &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;                                                                                                                            
&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token keyword"&gt;cards&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token data string"&gt;                                                                                                                                                          
203 1 Cv h4                                                                                                                                                     
203 2 Cv h2                                                                                                                                                     
205 1 Cv h0                                                                                                                                                     
205 2 Ah h3                                                                                                                                                     
205 3 Yro h0
;
&lt;BR /&gt;
%transpose(data=have, out=want, by=pronum, id=hor_nr,&amp;nbsp;var=hor_nr horiz humus)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2016 15:46:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transposing-multiple-variables/m-p/281421#M57071</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2016-06-30T15:46:59Z</dc:date>
    </item>
  </channel>
</rss>

