<?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 wide data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Transposing-wide-data/m-p/571826#M161332</link>
    <description>&lt;P&gt;It certainly works for me.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input county $ pop2014 pop2015 pop2016 pop2017 pop2018;
datalines;
A 100 200 300 400 500
B 150 250 350 450 550
;

proc transpose data=have out=want;
  by county;
  var pop:;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;Obs    county    _NAME_     COL1

  1      A       pop2014     100
  2      A       pop2015     200
  3      A       pop2016     300
  4      A       pop2017     400
  5      A       pop2018     500
  6      B       pop2014     150
  7      B       pop2015     250
  8      B       pop2016     350
  9      B       pop2017     450
 10      B       pop2018     550

&lt;/PRE&gt;
&lt;P&gt;You might want to post process it to convert the _NAME_ variable into a YEAR variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;year=input(substr(_name_,4),4.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could use a RENAME statement or the RENAME= dataset option to rename the COL1 variable into POPULATION or whatever name you want.&lt;/P&gt;</description>
    <pubDate>Mon, 08 Jul 2019 15:36:41 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-07-08T15:36:41Z</dc:date>
    <item>
      <title>Transposing wide data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-wide-data/m-p/571800#M161323</link>
      <description>&lt;P&gt;Have: Population data with one row per county, where each year's population is stored as a separate variable. (I'm new and couldn't figure out how to put a table in, sorry.) &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Want: A table with three columns, County, Year, and population.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using proc transpose and got a table with the county listed multiple times and the populations for each year, but it doesn't list what year the population data belongs to. Is there a way to output the name of the variable an observation was transposed from?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=pwid.popdata;
	by county;
run;

proc transpose data=pwid.popdata name=county let out=work.test;
	by county;
run;

proc print data=test; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2019 14:54:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-wide-data/m-p/571800#M161323</guid>
      <dc:creator>megsredl</dc:creator>
      <dc:date>2019-07-08T14:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing wide data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-wide-data/m-p/571816#M161328</link>
      <description>&lt;P&gt;Please provide an example of your input dataset.&lt;/P&gt;
&lt;P&gt;To give you a blueprint:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input county $ pop_2000 pop_2001 pop_2002;
datalines;
A 100 150 200
B 200 199 300
C 140 150 160
;

proc transpose data=have out=want;
by county;
var pop:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Jul 2019 15:16:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-wide-data/m-p/571816#M161328</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-08T15:16:40Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing wide data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-wide-data/m-p/571820#M161330</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input county $ pop2014 pop2015 pop2016 pop2017 pop2018;
datalines;
A 100 200 300 400 500
B 150 250 350 450 550&lt;BR /&gt;etc
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;My data is structured pretty much exactly how you wrote it. Running the transpose code didn't give me years/variable names though.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2019 15:25:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-wide-data/m-p/571820#M161330</guid>
      <dc:creator>megsredl</dc:creator>
      <dc:date>2019-07-08T15:25:56Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing wide data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-wide-data/m-p/571825#M161331</link>
      <description>&lt;P&gt;You will always get a variable _name_ from proc transpose that contains the name of the transposed variable.&lt;/P&gt;
&lt;P&gt;If you want to extract the year from the variable name, add a step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input county $ pop2014 pop2015 pop2016 pop2017 pop2018;
datalines;
A 100 200 300 400 500
B 150 250 350 450 550
;

proc transpose data=have out=trans;
by county;
var pop:;
run;

data want;
set trans;
rename col1=population;
year = input(compress(_name_,'','kd'),best.);
drop _name_;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;county    population    year

  A           100       2014
  A           200       2015
  A           300       2016
  A           400       2017
  A           500       2018
  B           150       2014
  B           250       2015
  B           350       2016
  B           450       2017
  B           550       2018
&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Jul 2019 15:36:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-wide-data/m-p/571825#M161331</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-08T15:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing wide data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-wide-data/m-p/571826#M161332</link>
      <description>&lt;P&gt;It certainly works for me.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input county $ pop2014 pop2015 pop2016 pop2017 pop2018;
datalines;
A 100 200 300 400 500
B 150 250 350 450 550
;

proc transpose data=have out=want;
  by county;
  var pop:;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;Obs    county    _NAME_     COL1

  1      A       pop2014     100
  2      A       pop2015     200
  3      A       pop2016     300
  4      A       pop2017     400
  5      A       pop2018     500
  6      B       pop2014     150
  7      B       pop2015     250
  8      B       pop2016     350
  9      B       pop2017     450
 10      B       pop2018     550

&lt;/PRE&gt;
&lt;P&gt;You might want to post process it to convert the _NAME_ variable into a YEAR variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;year=input(substr(_name_,4),4.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could use a RENAME statement or the RENAME= dataset option to rename the COL1 variable into POPULATION or whatever name you want.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2019 15:36:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-wide-data/m-p/571826#M161332</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-08T15:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing wide data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-wide-data/m-p/571829#M161333</link>
      <description>&lt;P&gt;You're right, I missed that it didn't have the let statement that I had in my code. For some reason that was suppressing output of the variable names. Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2019 15:41:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-wide-data/m-p/571829#M161333</guid>
      <dc:creator>megsredl</dc:creator>
      <dc:date>2019-07-08T15:41:40Z</dc:date>
    </item>
  </channel>
</rss>

