<?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: How to copy multiple variables with transpose in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-multiple-variables-with-transpose/m-p/523777#M142353</link>
    <description>&lt;P&gt;Try the %TRANSPOSE macro, written by members of this community&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings13/538-2013.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings13/538-2013.pdf&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 28 Dec 2018 17:06:45 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2018-12-28T17:06:45Z</dc:date>
    <item>
      <title>How to copy multiple variables with transpose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-multiple-variables-with-transpose/m-p/523771#M142349</link>
      <description>&lt;P&gt;I have a dataset that looks like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input block type $ count;
	datalines;
2 A 10
6 B 15
6 C 5
8 D 25
8 E 32
9 E 12
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and i want to transform it like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	infile datalines missover;
	input block type $ count type2 $ count2;
	datalines;
2 A 10
6 B 15 C 5
8 D 25 E 32
9 E 12
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In actuality my data has about 6M rows and can have up to 7 'types' for a given block.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Dec 2018 16:21:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-multiple-variables-with-transpose/m-p/523771#M142349</guid>
      <dc:creator>SAShole</dc:creator>
      <dc:date>2018-12-28T16:21:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy multiple variables with transpose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-multiple-variables-with-transpose/m-p/523773#M142350</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input block type $ count;
	datalines;
2 A 10
6 B 15
6 C 5
8 D 25
8 E 32
9 E 12
;
run;

data _h;
do n=1 by 1 until(last.block);
set have;
by block;
vn=cats(vname(type),n);
v=type;
output;
vn=cats(vname(count),n);
v=put(count,8. -l);
output;
end;
keep block vn v;
run;
proc transpose data=_h out=want(drop=_name_);
by block;
id vn;
var v ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Dec 2018 16:41:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-multiple-variables-with-transpose/m-p/523773#M142350</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-28T16:41:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy multiple variables with transpose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-multiple-variables-with-transpose/m-p/523775#M142351</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Another alternative, if you're going to have a DATA step and a PROC TRANSPOSE is to skip making 2 passes through the data (especially, if it's large data) and just have 1 DATA step using ARRAYs to transpose the data. If there is a possibility of a max of 7 for a block, that makes it easy to define the size of the ARRAY and this approach only makes 1 pass through the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; This does assume, however, that the data are sorted by BLOCK.&lt;/P&gt;
&lt;P&gt;Cynthia&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;
options missing=.;
data want(keep=block bcnt typ1 cnt1 typ2 cnt2 typ3 cnt3 typ4 cnt4
                    typ5 cnt5 typ6 cnt6 typ7 cnt7);
  set have;
  by block;
  array typ (7) $ typ1-typ7;
  array cnt(7)  cnt1-cnt7;
  retain bcnt typ1-typ7 cnt1-cnt7;
  if first.block then do;
     call missing(of typ1-typ7);
	 call missing(of cnt1-cnt7);
	 bcnt=0;
  end;
  bcnt+1;
  typ(bcnt) = type;
  cnt(bcnt) = count;
  if last.block then output;
run;

title; footnote;
proc print data=want;
  var block bcnt typ1 cnt1 typ2 cnt2 typ3 cnt3 typ4 cnt4
                    typ5 cnt5 typ6 cnt6 typ7 cnt7;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Dec 2018 16:50:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-multiple-variables-with-transpose/m-p/523775#M142351</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2018-12-28T16:50:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy multiple variables with transpose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-multiple-variables-with-transpose/m-p/523777#M142353</link>
      <description>&lt;P&gt;Try the %TRANSPOSE macro, written by members of this community&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings13/538-2013.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings13/538-2013.pdf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Dec 2018 17:06:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-multiple-variables-with-transpose/m-p/523777#M142353</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-12-28T17:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy multiple variables with transpose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-multiple-variables-with-transpose/m-p/523778#M142354</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by block type;
run;

proc transpose data=have out=count(drop=_name_) prefix=count;
by block;
var count;
run;
proc transpose data=have out=type(drop=_name_) prefix=type;
by block;
var type;
run;

data want;
merge type count;
by block;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Dec 2018 17:09:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-multiple-variables-with-transpose/m-p/523778#M142354</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-12-28T17:09:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy multiple variables with transpose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-multiple-variables-with-transpose/m-p/523780#M142356</link>
      <description>&lt;P&gt;Do you really want that structure?&amp;nbsp; Your example makes the TYPE values look like names.&amp;nbsp; Perhaps it would be better to treat them as such by using TYPE in an ID statement?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=want2 ;
  by block;
  id type;
  var count;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Obs    block    _NAME_     A     B    C     D     E

 1       2      count     10     .    .     .     .
 2       6      count      .    15    5     .     .
 3       8      count      .     .    .    25    32
 4       9      count      .     .    .     .    12
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Dec 2018 17:39:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-multiple-variables-with-transpose/m-p/523780#M142356</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-12-28T17:39:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy multiple variables with transpose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-multiple-variables-with-transpose/m-p/523791#M142358</link>
      <description>&lt;P&gt;Thank you everyone for your solutions! I truly appreciate the helpful responses I always get from this community &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Dec 2018 18:45:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-multiple-variables-with-transpose/m-p/523791#M142358</guid>
      <dc:creator>SAShole</dc:creator>
      <dc:date>2018-12-28T18:45:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy multiple variables with transpose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-multiple-variables-with-transpose/m-p/523797#M142359</link>
      <description>&lt;P&gt;This one is good example for using PROC SUMMARY.&amp;nbsp; Does not require sorting and will transpose both numeric and character at the same time without conversion.&amp;nbsp; You do have to know the max number of obs per CLASS group width maximum 100.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input block type $ count;
	datalines;
2 A 10
8 D 25
8 E 32
9 E 12
6 B 15
6 C 5
;
run;
proc print;
   run;
proc summary nway;
   class block;
   output out=wide(drop=_type_) idgroup(out[7](type count)=);
   run;
proc print;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/25907i3EE49301E53628E4/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Dec 2018 19:52:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-multiple-variables-with-transpose/m-p/523797#M142359</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2018-12-28T19:52:41Z</dc:date>
    </item>
  </channel>
</rss>

