<?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: Changing a two-dimensional-table to one-dimension in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Changing-a-two-dimensional-table-to-one-dimension/m-p/577162#M163523</link>
    <description>&lt;P&gt;Adapt next code to your data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   input country $3. value1-value5;
datalines;
AND 1 2 3 4 5
ATG 6 7 8 9 10
;
run;

data want;
     length coutry_code $8 ;
  set test;
    array year y1-y5;
	array vx valu1-value5;
	if _N_ = 1 then 
       do i=1 to 5;
	      yx(i) = i +1929;
	   end;
	do i=1 to 5;
	   country_code = cat('-',country,yx(i));
	   value = vx(i);
	end;
	keep country_code value;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 27 Jul 2019 14:04:43 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2019-07-27T14:04:43Z</dc:date>
    <item>
      <title>Changing a two-dimensional-table to one-dimension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-a-two-dimensional-table-to-one-dimension/m-p/577153#M163516</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my data is:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Country Code&lt;/TD&gt;&lt;TD&gt;1930&lt;/TD&gt;&lt;TD&gt;1931&lt;/TD&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;TD&gt;2018&lt;/TD&gt;&lt;TD&gt;2019&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AND&lt;/TD&gt;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;&lt;TD&gt;AND-2018&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AND-2019&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ATG-1930&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ATG-1931&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ATG-…&lt;/TD&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ATG-2018&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ATG-2019&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since this concatenates the names of rows and columns and reduces the dimension of the table,&lt;/P&gt;&lt;P&gt;I honestly don't know how to achieve it with functions such as transpose.&lt;/P&gt;&lt;P&gt;and for the original data, there are about 100 rows (100 different country codes) and 90 columns (from year 1930 - 2019)&lt;/P&gt;&lt;P&gt;Please help.&lt;/P&gt;</description>
      <pubDate>Sat, 27 Jul 2019 12:33:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-a-two-dimensional-table-to-one-dimension/m-p/577153#M163516</guid>
      <dc:creator>jimmychoi</dc:creator>
      <dc:date>2019-07-27T12:33:01Z</dc:date>
    </item>
    <item>
      <title>Re: Changing a two-dimensional-table to one-dimension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-a-two-dimensional-table-to-one-dimension/m-p/577156#M163518</link>
      <description>&lt;P&gt;It is not clear - is the 1st row part of your data? or is it the labels row?&lt;/P&gt;
&lt;P&gt;It seems that your input is an excel table. Have you imported it to sas?&lt;/P&gt;
&lt;P&gt;Are years successive from 1930 up to 2019 ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming your data is already a sas data set, please post your data in form of:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   input &amp;lt;variables&amp;gt;
datalines;

... your data ...

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 27 Jul 2019 12:45:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-a-two-dimensional-table-to-one-dimension/m-p/577156#M163518</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-07-27T12:45:01Z</dc:date>
    </item>
    <item>
      <title>Re: Changing a two-dimensional-table to one-dimension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-a-two-dimensional-table-to-one-dimension/m-p/577157#M163519</link>
      <description>&lt;P&gt;use proc transpose in reverse order&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Jul 2019 12:45:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-a-two-dimensional-table-to-one-dimension/m-p/577157#M163519</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2019-07-27T12:45:03Z</dc:date>
    </item>
    <item>
      <title>Re: Changing a two-dimensional-table to one-dimension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-a-two-dimensional-table-to-one-dimension/m-p/577159#M163520</link>
      <description>Hi Shmuel,&lt;BR /&gt;yes the first row is for the labels. and the years are successive from 1930 up to 2019.&lt;BR /&gt;For that reason, I couldn't write the data in datalines statement.</description>
      <pubDate>Sat, 27 Jul 2019 12:48:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-a-two-dimensional-table-to-one-dimension/m-p/577159#M163520</guid>
      <dc:creator>jimmychoi</dc:creator>
      <dc:date>2019-07-27T12:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: Changing a two-dimensional-table to one-dimension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-a-two-dimensional-table-to-one-dimension/m-p/577160#M163521</link>
      <description>Trying to read and understand the link...&lt;BR /&gt;</description>
      <pubDate>Sat, 27 Jul 2019 12:59:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-a-two-dimensional-table-to-one-dimension/m-p/577160#M163521</guid>
      <dc:creator>jimmychoi</dc:creator>
      <dc:date>2019-07-27T12:59:34Z</dc:date>
    </item>
    <item>
      <title>Re: Changing a two-dimensional-table to one-dimension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-a-two-dimensional-table-to-one-dimension/m-p/577161#M163522</link>
      <description>&lt;P&gt;here is a sample that does basically the samething.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Abun_dw20d_summary ;       informat bins $30.; format bins $30.; length bins $30.;
   input bins $ CM1DW20D CM3DW20D CW1DW20D ODWD W1DW4D;
   datalines;         
Acinetobacter 2477.123456789 195  163 45 77
Actinoalloteichus 2431 220  198 69.123456789 6774
Bacillus 2456 173  155 78 785
Bletilla 2412 135  116.123456789 45 123
;   
run;


proc transpose data=Abun_dw20d_summary out=bint;
    var _all_;
    by bins;
run;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 27 Jul 2019 13:46:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-a-two-dimensional-table-to-one-dimension/m-p/577161#M163522</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2019-07-27T13:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: Changing a two-dimensional-table to one-dimension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-a-two-dimensional-table-to-one-dimension/m-p/577162#M163523</link>
      <description>&lt;P&gt;Adapt next code to your data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   input country $3. value1-value5;
datalines;
AND 1 2 3 4 5
ATG 6 7 8 9 10
;
run;

data want;
     length coutry_code $8 ;
  set test;
    array year y1-y5;
	array vx valu1-value5;
	if _N_ = 1 then 
       do i=1 to 5;
	      yx(i) = i +1929;
	   end;
	do i=1 to 5;
	   country_code = cat('-',country,yx(i));
	   value = vx(i);
	end;
	keep country_code value;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 27 Jul 2019 14:04:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-a-two-dimensional-table-to-one-dimension/m-p/577162#M163523</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-07-27T14:04:43Z</dc:date>
    </item>
    <item>
      <title>Re: Changing a two-dimensional-table to one-dimension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-a-two-dimensional-table-to-one-dimension/m-p/577163#M163524</link>
      <description>&lt;P&gt;If you really have these column names, proc transpose is the way to go:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=trans;
by country_code;
var _numeric_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And then create the final dataset in an additional data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set trans (
  rename=(col1=value country_code=country);
);
length country_code $8;
country_code = catx('-',country,_name_);
drop country _name_;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 27 Jul 2019 14:15:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-a-two-dimensional-table-to-one-dimension/m-p/577163#M163524</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-27T14:15:03Z</dc:date>
    </item>
    <item>
      <title>Re: Changing a two-dimensional-table to one-dimension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-a-two-dimensional-table-to-one-dimension/m-p/577165#M163526</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Country_Code $ y1930 y1931 y2018 y2019;
cards;
AND
1
2
 
3
4
ATG
5
6
 
7
8
ABW
9
10
 
11
12
AUS
13
14
 
15
16
;
proc sort data=have;
	by country_code;
run;
proc transpose data=have out=want;
    var _all_;
    by country_code;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 27 Jul 2019 14:31:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-a-two-dimensional-table-to-one-dimension/m-p/577165#M163526</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2019-07-27T14:31:44Z</dc:date>
    </item>
    <item>
      <title>Re: Changing a two-dimensional-table to one-dimension</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-a-two-dimensional-table-to-one-dimension/m-p/577166#M163527</link>
      <description>Unless you have some special need that you haven't revealed, you would be much better off keeping the YEAR separate from the COUNTRY.  Several posters have shown how to do that using PROC TRANSPOSE.&lt;BR /&gt;&lt;BR /&gt;It's to your advantage to learn how to program with data in that form.  Here's just one example where three variables make the task easy but two variables make the task difficult:  find the average VALUE for each year.</description>
      <pubDate>Sat, 27 Jul 2019 14:52:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-a-two-dimensional-table-to-one-dimension/m-p/577166#M163527</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-07-27T14:52:10Z</dc:date>
    </item>
  </channel>
</rss>

