<?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 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Transposing/m-p/787140#M251439</link>
    <description>&lt;P&gt;Looks like some of the rows have FEMALE populated and the others have RACE populated.&lt;/P&gt;
&lt;P&gt;So test if those variables are missing or not to determine how to create value for VARIABLE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  length FEMALE 8 YEAR 8 RACE 8 pcnt $32;
  input FEMALE YEAR RACE pcnt;
cards;
0 2018 . 12900762(42.6%)
0 2019 . 12978685(43.0%)
1 2018 . 17356510(57.4%)
1 2019 . 17236228(57.0%)
. 2018 1 19747204(66.9%)
. 2019 1 19851043(67.2%)
. 2018 2 4453586(15.1%)
. 2019 2 4519150(15.3%)
. 2018 3 3394854(11.5%)
. 2019 3 3262700(11.1%)
. 2018 4 822329(2.8%)
. 2019 4 826270(2.8%)
. 2018 5 191580(0.6%)
. 2019 5 201155(0.7%)
. 2018 6 893325(3.0%)
. 2019 6 858436(2.9%)
;

data for_transpose;
  set have;
  length variable $32 ;
  if not missing(female) then variable=catx('_','FEMALE',female);
  else if not missing(race) then variable=catx('_','RACE',race);
run;

proc transpose data=for_transpose out=want(drop=_name_) prefix=Y_;
  by variable notsorted;
  id year ;
  var pcnt;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    variable        Y_2018             Y_2019

 1     FEMALE_0    12900762(42.6%)    12978685(43.0%)
 2     FEMALE_1    17356510(57.4%)    17236228(57.0%)
 3     RACE_1      19747204(66.9%)    19851043(67.2%)
 4     RACE_2      4453586(15.1%)     4519150(15.3%)
 5     RACE_3      3394854(11.5%)     3262700(11.1%)
 6     RACE_4      822329(2.8%)       826270(2.8%)
 7     RACE_5      191580(0.6%)       201155(0.7%)
 8     RACE_6      893325(3.0%)       858436(2.9%)
&lt;/PRE&gt;</description>
    <pubDate>Wed, 22 Dec 2021 17:18:39 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-12-22T17:18:39Z</dc:date>
    <item>
      <title>Transposing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing/m-p/787134#M251435</link>
      <description>&lt;P&gt;Hello dear friend,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Wish you all Happy Holidays and Happy New Year!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
infile cards missover;
format FEMALE 12. YEAR 12. RACE 12. pcnt $ 32.;
input FEMALE YEAR RACE pcnt;
cards;
0 2018 . 12900762(42.6%)
0 2019 . 12978685(43.0%)
1 2018 . 17356510(57.4%)
1 2019 . 17236228(57.0%)
. 2018 1 19747204(66.9%)
. 2019 1 19851043(67.2%)
. 2018 2 4453586(15.1%)
. 2019 2 4519150(15.3%)
. 2018 3 3394854(11.5%)
. 2019 3 3262700(11.1%)
. 2018 4 822329(2.8%)
. 2019 4 826270(2.8%)
. 2018 5 191580(0.6%)
. 2019 5 201155(0.7%)
. 2018 6 893325(3.0%)
. 2019 6 858436(2.9%)
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I am trying to transpose it to following:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
infile cards missover;
format Variable $ 32. Y_2018 $ 32. Y_2019 $ 32.;
input Variable Y_2018 Y_2019;
cards;
FEMALE_0 12900762(42.6%) 12978685(43.0%)
FEMALE_1 17356510(57.4%) 17236228(57.0%)
RACE_1 19747204(66.9%) 19851043(67.2%)
RACE_2 4453586(15.1%) 4519150(15.3%)
RACE_3 3394854(11.5%) 3262700(11.1%)
RACE_4 822329(2.8%) 826270(2.8%)
RACE_5 191580(0.6%) 201155(0.7%)
RACE_6 893325(3.0%) 858436(2.9%)
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I am struggling with creating the "Variable" and transpose. Could you please guide or help me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Rube&lt;/P&gt;</description>
      <pubDate>Wed, 22 Dec 2021 17:11:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing/m-p/787134#M251435</guid>
      <dc:creator>sandrube</dc:creator>
      <dc:date>2021-12-22T17:11:37Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing/m-p/787135#M251436</link>
      <description>&lt;P&gt;Create Variable using an IF/THEN condition followed by a standard transpose.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new_id;
set new;
if not missing(female) then category = catx("_", 'Female', female);
else category = catx("_", "RACE", race);

run;

proc sort data=new_id;
by category;
run;

proc transpose data=new_id out=want prefix=Y_;
by category;
id year;
var pcnt;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/272059"&gt;@sandrube&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello dear friend,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Wish you all Happy Holidays and Happy New Year!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following data:&lt;/P&gt;
&lt;P&gt;data new;&lt;BR /&gt;infile cards missover;&lt;BR /&gt;format FEMALE 12. YEAR 12. RACE 12. pcnt $ 32.;&lt;BR /&gt;input FEMALE YEAR RACE pcnt;&lt;BR /&gt;cards;&lt;BR /&gt;0 2018 . 12900762(42.6%)&lt;BR /&gt;0 2019 . 12978685(43.0%)&lt;BR /&gt;1 2018 . 17356510(57.4%)&lt;BR /&gt;1 2019 . 17236228(57.0%)&lt;BR /&gt;. 2018 1 19747204(66.9%)&lt;BR /&gt;. 2019 1 19851043(67.2%)&lt;BR /&gt;. 2018 2 4453586(15.1%)&lt;BR /&gt;. 2019 2 4519150(15.3%)&lt;BR /&gt;. 2018 3 3394854(11.5%)&lt;BR /&gt;. 2019 3 3262700(11.1%)&lt;BR /&gt;. 2018 4 822329(2.8%)&lt;BR /&gt;. 2019 4 826270(2.8%)&lt;BR /&gt;. 2018 5 191580(0.6%)&lt;BR /&gt;. 2019 5 201155(0.7%)&lt;BR /&gt;. 2018 6 893325(3.0%)&lt;BR /&gt;. 2019 6 858436(2.9%)&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to transpose it to following:&lt;/P&gt;
&lt;P&gt;data new;&lt;BR /&gt;infile cards missover;&lt;BR /&gt;format Variable $ 32. Y_2018 $ 32. Y_2019 $ 32.;&lt;BR /&gt;input Variable Y_2018 Y_2019;&lt;BR /&gt;cards;&lt;BR /&gt;FEMALE_0 12900762(42.6%) 12978685(43.0%)&lt;BR /&gt;FEMALE_1 17356510(57.4%) 17236228(57.0%)&lt;BR /&gt;RACE_1 19747204(66.9%) 19851043(67.2%)&lt;BR /&gt;RACE_2 4453586(15.1%) 4519150(15.3%)&lt;BR /&gt;RACE_3 3394854(11.5%) 3262700(11.1%)&lt;BR /&gt;RACE_4 822329(2.8%) 826270(2.8%)&lt;BR /&gt;RACE_5 191580(0.6%) 201155(0.7%)&lt;BR /&gt;RACE_6 893325(3.0%) 858436(2.9%)&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am struggling with creating the "Variable" and transpose. Could you please guide or help me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Rube&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Dec 2021 17:12:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing/m-p/787135#M251436</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-22T17:12:08Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing/m-p/787137#M251437</link>
      <description>&lt;P&gt;Ok for removing "run;"&lt;/P&gt;&lt;P&gt;Thank you very much for the explanation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rube&lt;/P&gt;</description>
      <pubDate>Wed, 22 Dec 2021 17:14:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing/m-p/787137#M251437</guid>
      <dc:creator>sandrube</dc:creator>
      <dc:date>2021-12-22T17:14:44Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing/m-p/787140#M251439</link>
      <description>&lt;P&gt;Looks like some of the rows have FEMALE populated and the others have RACE populated.&lt;/P&gt;
&lt;P&gt;So test if those variables are missing or not to determine how to create value for VARIABLE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  length FEMALE 8 YEAR 8 RACE 8 pcnt $32;
  input FEMALE YEAR RACE pcnt;
cards;
0 2018 . 12900762(42.6%)
0 2019 . 12978685(43.0%)
1 2018 . 17356510(57.4%)
1 2019 . 17236228(57.0%)
. 2018 1 19747204(66.9%)
. 2019 1 19851043(67.2%)
. 2018 2 4453586(15.1%)
. 2019 2 4519150(15.3%)
. 2018 3 3394854(11.5%)
. 2019 3 3262700(11.1%)
. 2018 4 822329(2.8%)
. 2019 4 826270(2.8%)
. 2018 5 191580(0.6%)
. 2019 5 201155(0.7%)
. 2018 6 893325(3.0%)
. 2019 6 858436(2.9%)
;

data for_transpose;
  set have;
  length variable $32 ;
  if not missing(female) then variable=catx('_','FEMALE',female);
  else if not missing(race) then variable=catx('_','RACE',race);
run;

proc transpose data=for_transpose out=want(drop=_name_) prefix=Y_;
  by variable notsorted;
  id year ;
  var pcnt;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    variable        Y_2018             Y_2019

 1     FEMALE_0    12900762(42.6%)    12978685(43.0%)
 2     FEMALE_1    17356510(57.4%)    17236228(57.0%)
 3     RACE_1      19747204(66.9%)    19851043(67.2%)
 4     RACE_2      4453586(15.1%)     4519150(15.3%)
 5     RACE_3      3394854(11.5%)     3262700(11.1%)
 6     RACE_4      822329(2.8%)       826270(2.8%)
 7     RACE_5      191580(0.6%)       201155(0.7%)
 8     RACE_6      893325(3.0%)       858436(2.9%)
&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Dec 2021 17:18:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing/m-p/787140#M251439</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-22T17:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing/m-p/787142#M251441</link>
      <description>&lt;P&gt;Thank you very much!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rube&lt;/P&gt;</description>
      <pubDate>Wed, 22 Dec 2021 17:29:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing/m-p/787142#M251441</guid>
      <dc:creator>sandrube</dc:creator>
      <dc:date>2021-12-22T17:29:23Z</dc:date>
    </item>
  </channel>
</rss>

