<?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 transpose a dataset based on one variable's value? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-transpose-a-dataset-based-on-one-variable-s-value/m-p/744439#M29308</link>
    <description>&lt;P&gt;Here you are.&lt;/P&gt;
&lt;P&gt;Use double transpose.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sample;
  input x y $;
datalines;
1 a
2 a
3 a
1 b
2 b
run;

PROC TRANSPOSE data=sample out=want1(drop=_NAME_);
 by y;
 var x;
run;

PROC TRANSPOSE data=want1 out=want2(drop=_NAME_);
 id y;
run;

proc print noobs; run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
    <pubDate>Fri, 28 May 2021 15:17:22 GMT</pubDate>
    <dc:creator>sbxkoenk</dc:creator>
    <dc:date>2021-05-28T15:17:22Z</dc:date>
    <item>
      <title>How to transpose a dataset based on one variable's value?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-transpose-a-dataset-based-on-one-variable-s-value/m-p/744428#M29307</link>
      <description>&lt;P&gt;Hi, I have a data like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sample;
  input x y $;
datalines;
1 a
2 a
3 a
1 b
2 b
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is it possible to transpose this data to print out like this:&lt;/P&gt;&lt;P&gt;a b&lt;/P&gt;&lt;P&gt;1 1&lt;/P&gt;&lt;P&gt;2 2&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 28 May 2021 14:50:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-transpose-a-dataset-based-on-one-variable-s-value/m-p/744428#M29307</guid>
      <dc:creator>cosmid</dc:creator>
      <dc:date>2021-05-28T14:50:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to transpose a dataset based on one variable's value?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-transpose-a-dataset-based-on-one-variable-s-value/m-p/744439#M29308</link>
      <description>&lt;P&gt;Here you are.&lt;/P&gt;
&lt;P&gt;Use double transpose.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sample;
  input x y $;
datalines;
1 a
2 a
3 a
1 b
2 b
run;

PROC TRANSPOSE data=sample out=want1(drop=_NAME_);
 by y;
 var x;
run;

PROC TRANSPOSE data=want1 out=want2(drop=_NAME_);
 id y;
run;

proc print noobs; run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Fri, 28 May 2021 15:17:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-transpose-a-dataset-based-on-one-variable-s-value/m-p/744439#M29308</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-05-28T15:17:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to transpose a dataset based on one variable's value?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-transpose-a-dataset-based-on-one-variable-s-value/m-p/744441#M29309</link>
      <description>&lt;P&gt;The easiest way to have variables names derived from data is to use PROC TRANSPOSE.&lt;/P&gt;
&lt;P&gt;It looks you want to use Y in the ID statement and X in the VAR statement.&lt;/P&gt;
&lt;P&gt;But you need a third variable to indicate which observations to group together.&amp;nbsp; You could try to use X for that also.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sample;
  input x y $;
datalines;
1 a
2 a
3 a
1 b
2 b
;

proc sort data=sample;
  by x y;
run;

proc transpose data=sample out=want(drop=_name_);
  by x;
  id y;
  var x;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;Obs    x    a    b

 1     1    1    1
 2     2    2    2
 3     3    3    .

&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 May 2021 15:19:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-transpose-a-dataset-based-on-one-variable-s-value/m-p/744441#M29309</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-28T15:19:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to transpose a dataset based on one variable's value?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-transpose-a-dataset-based-on-one-variable-s-value/m-p/744611#M29316</link>
      <description>&lt;P&gt;Merge skill proposed by me and Arthur.T .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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 sample;
  input x y $;
datalines;
1 a
2 a
3 a
1 b
2 b
;

proc sql noprint;
select distinct catt('sample(where=(y="',y,'") rename=(x=',y,'))') into : merge separated by ' '
 from sample;
quit;

data want;
 merge &amp;amp;merge;
 drop y;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 29 May 2021 12:12:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-transpose-a-dataset-based-on-one-variable-s-value/m-p/744611#M29316</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-05-29T12:12:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to transpose a dataset based on one variable's value?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-transpose-a-dataset-based-on-one-variable-s-value/m-p/745032#M29337</link>
      <description>Hi, thanks for the code. It seems after the first Transpose, the var y is lost?</description>
      <pubDate>Tue, 01 Jun 2021 19:55:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-transpose-a-dataset-based-on-one-variable-s-value/m-p/745032#M29337</guid>
      <dc:creator>cosmid</dc:creator>
      <dc:date>2021-06-01T19:55:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to transpose a dataset based on one variable's value?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-transpose-a-dataset-based-on-one-variable-s-value/m-p/745033#M29338</link>
      <description>Thank you for the code! It works! However, how do I make the result to just print a and b without the x? I have to add a print statement to make this work. And regarding the code, are these correct:&lt;BR /&gt;1. by x, I am assuming it's grouping by x, but what does that really mean?&lt;BR /&gt;2. id y, it's using y's value as the column header?&lt;BR /&gt;3. var x, this is the variable that is going to be transported based on the y's value?&lt;BR /&gt;&lt;BR /&gt;Thanks!</description>
      <pubDate>Tue, 01 Jun 2021 19:55:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-transpose-a-dataset-based-on-one-variable-s-value/m-p/745033#M29338</guid>
      <dc:creator>cosmid</dc:creator>
      <dc:date>2021-06-01T19:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to transpose a dataset based on one variable's value?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-transpose-a-dataset-based-on-one-variable-s-value/m-p/745035#M29339</link>
      <description>also, I accidentally accepted my reply as a solution. I couldn't find the button to delete that as the solution and accept your reply as the solution. Sorry!</description>
      <pubDate>Tue, 01 Jun 2021 19:57:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-transpose-a-dataset-based-on-one-variable-s-value/m-p/745035#M29339</guid>
      <dc:creator>cosmid</dc:creator>
      <dc:date>2021-06-01T19:57:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to transpose a dataset based on one variable's value?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-transpose-a-dataset-based-on-one-variable-s-value/m-p/745037#M29340</link>
      <description>Wow! This code works and prints out the exact information and format. I read the paper provided by the link and still couldn't understand how the code works. I think I should really think about pursuing a career in SAS.&lt;BR /&gt;&lt;BR /&gt;Thank you for the help!</description>
      <pubDate>Tue, 01 Jun 2021 20:11:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-transpose-a-dataset-based-on-one-variable-s-value/m-p/745037#M29340</guid>
      <dc:creator>cosmid</dc:creator>
      <dc:date>2021-06-01T20:11:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to transpose a dataset based on one variable's value?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-transpose-a-dataset-based-on-one-variable-s-value/m-p/745044#M29341</link>
      <description>&lt;P&gt;If you do not include a BY statement in PROC TRANPOSE then the number of variables will equal the number of observations and the number of observations will equal the number of variables you are transposing.&amp;nbsp; When you use the BY statement you let it know how to group the data so that all of the observations for the same group get transposed together.&amp;nbsp; Now the number of variables is the maximum number of observations for any group and the number of observations is the number of distinct groups times the number of variables being transposed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The ID statement is how you tell it what variables' values to use to name the new variables it is creating.&amp;nbsp; In your case you requested that the values of Y become the names of the new variables.&amp;nbsp; Without an ID statement it will just number the variables COL1, COL2, .... (you can change COL to some other text by using the PREFIX= option of the PROC TRANSPOSE statement).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The VAR statement says which variables values are going be transposed.&amp;nbsp; If you leave off this statement it will transpose all of the numeric variables in your dataset.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jun 2021 12:28:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-transpose-a-dataset-based-on-one-variable-s-value/m-p/745044#M29341</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-02T12:28:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to transpose a dataset based on one variable's value?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-transpose-a-dataset-based-on-one-variable-s-value/m-p/745140#M29343</link>
      <description>You can put the macro varible:&lt;BR /&gt;&lt;BR /&gt;%put &amp;amp;merge;&lt;BR /&gt;&lt;BR /&gt;And you would know what happened .</description>
      <pubDate>Wed, 02 Jun 2021 11:32:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-transpose-a-dataset-based-on-one-variable-s-value/m-p/745140#M29343</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-06-02T11:32:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to transpose a dataset based on one variable's value?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-transpose-a-dataset-based-on-one-variable-s-value/m-p/745317#M29349</link>
      <description>Wow, thank you Professor Tom for the detailed explanation! Appreciate it!</description>
      <pubDate>Wed, 02 Jun 2021 20:50:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-transpose-a-dataset-based-on-one-variable-s-value/m-p/745317#M29349</guid>
      <dc:creator>cosmid</dc:creator>
      <dc:date>2021-06-02T20:50:59Z</dc:date>
    </item>
  </channel>
</rss>

