<?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: transpose data (more than one variable) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/transpose-data-more-than-one-variable/m-p/615156#M179922</link>
    <description>&lt;P&gt;Just a note to consider ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Most of the time, transposing in this fashion creates more problems than it solves. &amp;nbsp;Unless you are just intending to print the transposed data, you would usually be better off keeping the data in its current form and learning to program with it in that form.&lt;/P&gt;</description>
    <pubDate>Sun, 05 Jan 2020 01:01:31 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2020-01-05T01:01:31Z</dc:date>
    <item>
      <title>transpose data (more than one variable)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transpose-data-more-than-one-variable/m-p/615152#M179918</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm trying to solve this problem.&lt;/P&gt;&lt;P&gt;I have this dataset&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input facility mortgage $ id $ name $;
	datalines;
1 A 001 Jhon
1 B 003 Frank
2 C 004 Tom
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And I'd like to view my data in this other way&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	infile datalines missover;
	input facility mortgage_1 $ id_1 $ name_1 $ mortgage_2 $ id_2 $ name_2 $ ;
datalines;
1 A 001 Jhon B 003 Frank
2 C 004 Tom
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I think I have to use "proc transpose" but I don't know how...could someone help me!! Thanks a lot!&lt;/P&gt;&lt;P&gt;Daniele&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jan 2020 22:00:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transpose-data-more-than-one-variable/m-p/615152#M179918</guid>
      <dc:creator>Ccasagran737</dc:creator>
      <dc:date>2020-01-04T22:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: transpose data (more than one variable)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transpose-data-more-than-one-variable/m-p/615153#M179919</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/175761"&gt;@Ccasagran737&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IDGROUP transpose using Proc summary is slick for this type.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
	input facility mortgage $ id $ name $;
	datalines;
1 A 001 Jhon
1 B 003 Frank
2 C 004 Tom
;
run;


proc sql noprint; 
 select max(obs) into :obs 
from ( select count(*) as obs from have group by facility ) ;
 quit;

proc summary nway data=have missing; 
 class facility; 
 output out = want(drop=_type_ _freq_) 
 idgroup(out[&amp;amp;obs](mortgage id name)=) ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 04 Jan 2020 22:07:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transpose-data-more-than-one-variable/m-p/615153#M179919</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-04T22:07:59Z</dc:date>
    </item>
    <item>
      <title>Re: transpose data (more than one variable)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transpose-data-more-than-one-variable/m-p/615154#M179920</link>
      <description>&lt;P&gt;Hello again&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/175761"&gt;@Ccasagran737&lt;/a&gt;&amp;nbsp; &amp;nbsp;Perhaps you could be more familiar with the following approach.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input facility mortgage $ id $ name $;
	datalines;
1 A 001 Jhon
1 B 003 Frank
2 C 004 Tom
;
run;

data temp;
 do _n_=1 by 1 until(last.facility);
  set have;
  by facility;
  array t mortgage id name;
  length vn  $32;
  do over t;
  vn=catx('_',vname(t),_n_);
  temp=t;
  output;
  end;
 end;
 keep facility vn temp;
run;

proc transpose data=temp out=want(drop=_name_) ;
by facility;
var temp;
id vn;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;
&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jan 2020 23:14:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transpose-data-more-than-one-variable/m-p/615154#M179920</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-04T23:14:55Z</dc:date>
    </item>
    <item>
      <title>Re: transpose data (more than one variable)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transpose-data-more-than-one-variable/m-p/615156#M179922</link>
      <description>&lt;P&gt;Just a note to consider ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Most of the time, transposing in this fashion creates more problems than it solves. &amp;nbsp;Unless you are just intending to print the transposed data, you would usually be better off keeping the data in its current form and learning to program with it in that form.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jan 2020 01:01:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transpose-data-more-than-one-variable/m-p/615156#M179922</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-01-05T01:01:31Z</dc:date>
    </item>
    <item>
      <title>Re: transpose data (more than one variable)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transpose-data-more-than-one-variable/m-p/615162#M179925</link>
      <description>&lt;P&gt;Transform to long, then back to wide, like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input facility mortgage $ id $ name $;
	datalines;
1 A 001 Jhon
1 B 003 Frank
2 C 004 Tom
;

data temp;
length value $16;
do i = 1 by 1 until(last.facility);
	set have; by facility;
	var = "mortgage"; value = mortgage; output;
	var = "id"; value = id; output;
	var = "name"; value = name; output;
	end;
drop mortgage id name;
run;

proc transpose data=temp out=want delimiter=_;
by facility;
id var i;
var value;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 Jan 2020 03:07:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transpose-data-more-than-one-variable/m-p/615162#M179925</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-01-05T03:07:29Z</dc:date>
    </item>
    <item>
      <title>Re: transpose data (more than one variable)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transpose-data-more-than-one-variable/m-p/615170#M179930</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/175761"&gt;@Ccasagran737&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is another way to achieve this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
	select max(count) into:count
	from (select count(facility) as count from have group by facility);
quit;

data want;
	set have;
	by facility;
	
	/* definition of new columns */
	array mortgage_ (&amp;amp;count) $;
	array id_ (&amp;amp;count) $;
	array name_ (&amp;amp;count) $;
	
	/* reinitialization for each new facility */
	if first.facility then do;
		counter = 0;
		call missing (of mortgage_(*));
		call missing (of id_(*));
		call missing (of name_(*));
	end;
	
	/* calculation of new variables */
	retain mortgage_;
	retain id_;
	retain name_;
	
	counter + 1;

	do i=1 to &amp;amp;count;
		mortgage_(counter) = mortgage;
		id_(counter) = id;
		name_(counter) = name;
	end;
	
	if last.facility then output;
	
	drop i counter mortgage id name;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 Jan 2020 08:57:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transpose-data-more-than-one-variable/m-p/615170#M179930</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-01-05T08:57:26Z</dc:date>
    </item>
    <item>
      <title>Re: transpose data (more than one variable)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transpose-data-more-than-one-variable/m-p/615174#M179932</link>
      <description>&lt;P&gt;MERGE skill :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
	input facility mortgage $ id $ name $;
	datalines;
1 A 001 Jhon
1 B 003 Frank
2 C 004 Tom
;
run;


data have ;
set have;
by facility;
if first.facility then n=0;
n+1;
run;
proc sql noprint;
select distinct catt('have(where=(n=',n,') rename=
(mortgage=mortgage_',n,' id=id_',n,' name=name_',n,'))')
into : merge separated by ' '
from have;
quit;
data want;
 merge &amp;amp;merge ;
 by facility;
 drop n;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 Jan 2020 10:32:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transpose-data-more-than-one-variable/m-p/615174#M179932</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-01-05T10:32:50Z</dc:date>
    </item>
    <item>
      <title>Re: transpose data (more than one variable)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transpose-data-more-than-one-variable/m-p/615482#M180032</link>
      <description>&lt;P&gt;Hi. I'm studying your program. I don't know this writing&amp;nbsp;&lt;SPAN&gt;',n,'. Could you help me understand how does it works. Thanks a lot.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Daniele&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2020 21:44:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transpose-data-more-than-one-variable/m-p/615482#M180032</guid>
      <dc:creator>Ccasagran737</dc:creator>
      <dc:date>2020-01-06T21:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: transpose data (more than one variable)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transpose-data-more-than-one-variable/m-p/615612#M180073</link>
      <description>&lt;PRE&gt;%put &amp;amp;merge ;
&lt;/PRE&gt;
&lt;P&gt;could display the code I try to build up .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
 merge

have(where=(n=1) rename=(mortgage=mortgage_1 id=id_1 name=name_1)) have(where=(n=2) rename=(mortgage=mortgage_2 id=id_2 name=name_2))

;
 by facility;
 drop n;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Jan 2020 10:40:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transpose-data-more-than-one-variable/m-p/615612#M180073</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-01-07T10:40:43Z</dc:date>
    </item>
  </channel>
</rss>

