<?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 split a dataset into n number of tables based on variable name in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-dataset-into-n-number-of-tables-based-on-variable/m-p/883668#M82823</link>
    <description>&lt;P&gt;First let's convert your listing into an actual dataset.&amp;nbsp; If those are your actual variable names (instead of just the labels used in the printing) then you will have to have the VALIDVARNAME option set to ANY to be able to use the dataset.&amp;nbsp; Also number cannot have two decimal points.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options validvarname=any;
data have;
  input 'Merti name'n $  'jan-23'n 'feb-23'n 'mar-23'n ;
cards;
A. 1. 2. 9
B. 2.2 4. 8
C. 2.5 5 7
D. 3. 3. 6
E. 4. 5. 7
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So just transpose the dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=want name=date ;
  by 'Merti name'n;
  var 'jan-23'n 'feb-23'n 'mar-23'n;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;       Merti
Obs    name      date     COL1

  1     A.      jan-23     1.0
  2     A.      feb-23     2.0
  3     A.      mar-23     9.0
  4     B.      jan-23     2.2
  5     B.      feb-23     4.0
  6     B.      mar-23     8.0
  7     C.      jan-23     2.5
  8     C.      feb-23     5.0
  9     C.      mar-23     7.0
 10     D.      jan-23     3.0
 11     D.      feb-23     3.0
 12     D.      mar-23     6.0
 13     E.      jan-23     4.0
 14     E.      feb-23     5.0
 15     E.      mar-23     7.0

&lt;/PRE&gt;</description>
    <pubDate>Thu, 06 Jul 2023 04:34:21 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-07-06T04:34:21Z</dc:date>
    <item>
      <title>How to split a dataset into n number of tables based on variable name</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-dataset-into-n-number-of-tables-based-on-variable/m-p/883621#M82818</link>
      <description>I have a dataset with multiple columns in it. One column contains the name of the metrics and the rest of them are having summary level information for those metrics on a monthly level.&lt;BR /&gt;I want to split these month level information and then append the data again so thay i can have that monthly data appened vertically to the prior month rather than havin a horizontal view of the data. Unfortunately i cannot share the data here. But if any has any suggestions to give that would be highly appreciated.</description>
      <pubDate>Wed, 05 Jul 2023 20:09:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-dataset-into-n-number-of-tables-based-on-variable/m-p/883621#M82818</guid>
      <dc:creator>Programmer26</dc:creator>
      <dc:date>2023-07-05T20:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a dataset into n number of tables based on variable name</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-dataset-into-n-number-of-tables-based-on-variable/m-p/883626#M82819</link>
      <description>&lt;P&gt;Can you show sample records of what you have and what you want?&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2023 20:35:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-dataset-into-n-number-of-tables-based-on-variable/m-p/883626#M82819</guid>
      <dc:creator>john_mccall</dc:creator>
      <dc:date>2023-07-05T20:35:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a dataset into n number of tables based on variable name</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-dataset-into-n-number-of-tables-based-on-variable/m-p/883631#M82820</link>
      <description>&lt;P&gt;Sounds like you are describing a TRANSPOSE.&lt;/P&gt;
&lt;P&gt;So assuming the data is sorted by your METRIC variable this step&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=want name=datestr ;
  by metric;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Will create a new dataset by transposing all of the numeric variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you said the different variables represented different MONTHS I has it store the original name of the variable into a new variable named DATESTR.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to convert that character string into an any actual date value then it will depend on how the month is recorded in the variable name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS&amp;nbsp; Post example data.&amp;nbsp; It does not have to be your REAL data, just something that is close enough that you can adjust the proposed answers to work on your real data.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2023 20:42:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-dataset-into-n-number-of-tables-based-on-variable/m-p/883631#M82820</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-07-05T20:42:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a dataset into n number of tables based on variable name</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-dataset-into-n-number-of-tables-based-on-variable/m-p/883665#M82821</link>
      <description>Below is the example of how my actual data looks like and how i want to represent it.&lt;BR /&gt;Input data&lt;BR /&gt;Merti name jan-23 feb-23 mar-23&lt;BR /&gt;A. 1. 2. 9&lt;BR /&gt;B. 2.2. 4. 8&lt;BR /&gt;C. 2.5. 5 7&lt;BR /&gt;D. 3. 3. 6&lt;BR /&gt;E. 4. 5. 7&lt;BR /&gt;&lt;BR /&gt;Output data&lt;BR /&gt;Metric_name date. Value&lt;BR /&gt;A. Jan-23 1&lt;BR /&gt;B. Jan-23. 2.2&lt;BR /&gt;C. Jan-23. 2.5&lt;BR /&gt;D. Jan-23. 3&lt;BR /&gt;E. Jan-23. 4&lt;BR /&gt;A. Feb-23. 2&lt;BR /&gt;B. Feb-23. 4&lt;BR /&gt;C. Feb-23. 5&lt;BR /&gt;D. Feb-23. 3&lt;BR /&gt;E. Feb-23. 5</description>
      <pubDate>Thu, 06 Jul 2023 04:08:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-dataset-into-n-number-of-tables-based-on-variable/m-p/883665#M82821</guid>
      <dc:creator>Programmer26</dc:creator>
      <dc:date>2023-07-06T04:08:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a dataset into n number of tables based on variable name</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-dataset-into-n-number-of-tables-based-on-variable/m-p/883666#M82822</link>
      <description>Below is the example of how my actual data looks like and how i want to represent it.&lt;BR /&gt;Input data&lt;BR /&gt;Merti name jan-23 feb-23 mar-23&lt;BR /&gt;A 1 2 9&lt;BR /&gt;B 2.2 4 8&lt;BR /&gt;C 2.5 5 7&lt;BR /&gt;D 3 3 6&lt;BR /&gt;E 4 5 7&lt;BR /&gt;&lt;BR /&gt;Output data&lt;BR /&gt;Metric_name date Value&lt;BR /&gt;A Jan-23 1&lt;BR /&gt;B Jan-23 2.2&lt;BR /&gt;C Jan-23 2.5&lt;BR /&gt;D Jan-23 3&lt;BR /&gt;E Jan-23 4&lt;BR /&gt;A Feb-23. 2&lt;BR /&gt;B Feb-23 4&lt;BR /&gt;C Feb-23 5&lt;BR /&gt;D Feb-23 3&lt;BR /&gt;E Feb-23 5</description>
      <pubDate>Thu, 06 Jul 2023 04:12:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-dataset-into-n-number-of-tables-based-on-variable/m-p/883666#M82822</guid>
      <dc:creator>Programmer26</dc:creator>
      <dc:date>2023-07-06T04:12:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a dataset into n number of tables based on variable name</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-dataset-into-n-number-of-tables-based-on-variable/m-p/883668#M82823</link>
      <description>&lt;P&gt;First let's convert your listing into an actual dataset.&amp;nbsp; If those are your actual variable names (instead of just the labels used in the printing) then you will have to have the VALIDVARNAME option set to ANY to be able to use the dataset.&amp;nbsp; Also number cannot have two decimal points.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options validvarname=any;
data have;
  input 'Merti name'n $  'jan-23'n 'feb-23'n 'mar-23'n ;
cards;
A. 1. 2. 9
B. 2.2 4. 8
C. 2.5 5 7
D. 3. 3. 6
E. 4. 5. 7
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So just transpose the dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=want name=date ;
  by 'Merti name'n;
  var 'jan-23'n 'feb-23'n 'mar-23'n;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;       Merti
Obs    name      date     COL1

  1     A.      jan-23     1.0
  2     A.      feb-23     2.0
  3     A.      mar-23     9.0
  4     B.      jan-23     2.2
  5     B.      feb-23     4.0
  6     B.      mar-23     8.0
  7     C.      jan-23     2.5
  8     C.      feb-23     5.0
  9     C.      mar-23     7.0
 10     D.      jan-23     3.0
 11     D.      feb-23     3.0
 12     D.      mar-23     6.0
 13     E.      jan-23     4.0
 14     E.      feb-23     5.0
 15     E.      mar-23     7.0

&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Jul 2023 04:34:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-dataset-into-n-number-of-tables-based-on-variable/m-p/883668#M82823</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-07-06T04:34:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a dataset into n number of tables based on variable name</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-dataset-into-n-number-of-tables-based-on-variable/m-p/883683#M82824</link>
      <description>&lt;P&gt;I'll make some guesses about your data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options validvarname=any;

data have;
input metric_name $ 'jan-23'n 'feb-23'n 'mar-23'n;
datalines;
A 1 2 9
B 2.2 4 8
C 2.5 5 7
D 3 3 6
E 4 5 7
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;First, transpose to long:'&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=long (rename=(col1=value));
by metric_name;
var _numeric_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then, convert the dates:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set long;
date = input(compress(_name_,"-),monyy5.);
format date yymmd7.;
drop _name_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Finally, sort as wanted:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=want;
by date metric_name;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2023 08:39:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-dataset-into-n-number-of-tables-based-on-variable/m-p/883683#M82824</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-07-06T08:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a dataset into n number of tables based on variable name</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-dataset-into-n-number-of-tables-based-on-variable/m-p/884404#M82825</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/383419"&gt;@Programmer26&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Below is the example of how my actual data looks like and how i want to represent it.&lt;BR /&gt;Input data&lt;BR /&gt;Merti name jan-23 feb-23 mar-23&lt;BR /&gt;A 1 2 9&lt;BR /&gt;B 2.2 4 8&lt;BR /&gt;C 2.5 5 7&lt;BR /&gt;D 3 3 6&lt;BR /&gt;E 4 5 7&lt;BR /&gt;&lt;BR /&gt;Output data&lt;BR /&gt;Metric_name date Value&lt;BR /&gt;A Jan-23 1&lt;BR /&gt;B Jan-23 2.2&lt;BR /&gt;C Jan-23 2.5&lt;BR /&gt;D Jan-23 3&lt;BR /&gt;E Jan-23 4&lt;BR /&gt;A Feb-23. 2&lt;BR /&gt;B Feb-23 4&lt;BR /&gt;C Feb-23 5&lt;BR /&gt;D Feb-23 3&lt;BR /&gt;E Feb-23 5&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Can be done directly reading a text file with that structure. Example:&lt;/P&gt;
&lt;PRE&gt;data want;
   input metric_name $ @;
   do month=1 to 3;
      date=mdy(month,1,2023);
      input value @;
      output;
   end;
   input;
   format date Monyy7.;
   drop month;
datalines;
A 1 2 9
B 2.2 4 8
C 2.5 5 7
D 3 3 6
E 4 5 7
;&lt;/PRE&gt;
&lt;P&gt;Once upon a time I inherited 30+ years worth of "data" that existed as report tables. A single file that had header information as to site, type of measurement(s) and year. Then the bulk of the "data" for a measure year was structured with 12 columns (months) and 31 rows (days). So the "trick" was to read the file starting at the right position for each piece of data and generate the appropriate date values using the column / row position.&lt;/P&gt;
&lt;P&gt;The program above uses the @ on the first Input to hold the reading pointer on the line after reading the metric. Then since your example hat 3 months use a counter to input set a month value and the MDY function to create a date using the column counter (month) and fixed day and year along with input to read the value. The output writes each value as read. The last input without @ is to advance to the next line of the file.&lt;/P&gt;
&lt;P&gt;I refuse to use any 2 digit years so have the MONYY7 format. If you insist on the possibly confusing 2-digit year you can use a different format.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2023 22:35:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-dataset-into-n-number-of-tables-based-on-variable/m-p/884404#M82825</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-07-11T22:35:14Z</dc:date>
    </item>
  </channel>
</rss>

