<?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: Transforming data from horizontal to vertical in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Transforming-data-from-horizontal-to-vertical/m-p/895896#M353961</link>
    <description>&lt;P&gt;Some of my work has noticed increased speed from running the transposition in a data step, but I'm unsure if that always holds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input person $1. status_january status_february status_march;
datalines;
A 2 3 2
B 4 4 4
C 3 2 3
;
run;

data want (drop = status_: i);
	set have;
	array _s [*] status_:;
	do i = 1 to dim(_s);
		status = _s[i];
		time = propcase(scan(vname(_s[i]), -1, '_'));
		person = person;
		output;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now, do you actually have commas in your variable names? I substituted with underscores to make working code.&lt;/P&gt;
&lt;P&gt;Nonetheless, here's my output:&lt;/P&gt;
&lt;PRE&gt;person	status	time
A	2	January
A	3	February
A	2	March
B	4	January
B	4	February
B	4	March
C	3	January
C	2	February
C	3	March&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;PROC TRANSPOSE is generally easier to understand.&lt;/P&gt;</description>
    <pubDate>Tue, 26 Sep 2023 13:13:28 GMT</pubDate>
    <dc:creator>maguiremq</dc:creator>
    <dc:date>2023-09-26T13:13:28Z</dc:date>
    <item>
      <title>Transforming data from horizontal to vertical</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transforming-data-from-horizontal-to-vertical/m-p/895892#M353958</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have this data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="1" width="63.99954832881662%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="20%" height="30px"&gt;Person&lt;/TD&gt;
&lt;TD width="20%" height="30px"&gt;Status, january&lt;/TD&gt;
&lt;TD width="20%" height="30px"&gt;Status, february&lt;/TD&gt;
&lt;TD width="20%" height="30px"&gt;Status, march&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="20%" height="30px"&gt;A&lt;/TD&gt;
&lt;TD width="20%" height="30px"&gt;2&lt;/TD&gt;
&lt;TD width="20%" height="30px"&gt;3&lt;/TD&gt;
&lt;TD width="20%" height="30px"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="20%" height="30px"&gt;B&lt;/TD&gt;
&lt;TD width="20%" height="30px"&gt;4&lt;/TD&gt;
&lt;TD width="20%" height="30px"&gt;4&lt;/TD&gt;
&lt;TD width="20%" height="30px"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="20%" height="30px"&gt;C&lt;/TD&gt;
&lt;TD width="20%" height="30px"&gt;3&lt;/TD&gt;
&lt;TD width="20%" height="30px"&gt;2&lt;/TD&gt;
&lt;TD width="20%" height="30px"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And I need it transformed to this data:&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;Person&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;Time&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;Status&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;A&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;January&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;A&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;February&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;A&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;March&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;B&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;January&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;B&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;February&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;B&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;March&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;C&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;January&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;C&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;February&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;C&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;March&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone help me do this? Thanks a lot &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2023 12:57:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transforming-data-from-horizontal-to-vertical/m-p/895892#M353958</guid>
      <dc:creator>niki0209</dc:creator>
      <dc:date>2023-09-26T12:57:38Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming data from horizontal to vertical</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transforming-data-from-horizontal-to-vertical/m-p/895895#M353960</link>
      <description>&lt;P&gt;This code will perform the task for you, under an important assumption.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=want;
    by person;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The assumption is that you are actually working with a valid SAS data set with valid SAS variable names; and not this apparent Excel file that you show.&amp;nbsp; Valid SAS variable names cannot have commas or spaces in the variable name, so you have to fix that.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From now on, please provide data as working SAS data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;examples and instructions&lt;/A&gt;) and not as Excel or Excel copy and paste into the window where you type your message.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2023 13:10:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transforming-data-from-horizontal-to-vertical/m-p/895895#M353960</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-09-26T13:10:48Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming data from horizontal to vertical</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transforming-data-from-horizontal-to-vertical/m-p/895896#M353961</link>
      <description>&lt;P&gt;Some of my work has noticed increased speed from running the transposition in a data step, but I'm unsure if that always holds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input person $1. status_january status_february status_march;
datalines;
A 2 3 2
B 4 4 4
C 3 2 3
;
run;

data want (drop = status_: i);
	set have;
	array _s [*] status_:;
	do i = 1 to dim(_s);
		status = _s[i];
		time = propcase(scan(vname(_s[i]), -1, '_'));
		person = person;
		output;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now, do you actually have commas in your variable names? I substituted with underscores to make working code.&lt;/P&gt;
&lt;P&gt;Nonetheless, here's my output:&lt;/P&gt;
&lt;PRE&gt;person	status	time
A	2	January
A	3	February
A	2	March
B	4	January
B	4	February
B	4	March
C	3	January
C	2	February
C	3	March&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;PROC TRANSPOSE is generally easier to understand.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2023 13:13:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transforming-data-from-horizontal-to-vertical/m-p/895896#M353961</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2023-09-26T13:13:28Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming data from horizontal to vertical</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transforming-data-from-horizontal-to-vertical/m-p/895897#M353962</link>
      <description>&lt;P&gt;Hi. Thanks for trying to help, but it doesn't seem to work.&lt;/P&gt;
&lt;P&gt;(Yes, I am working with a proper SAS dataset - I just made up some variables names quickly).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I use the code it just gives me an empty data set.&lt;/P&gt;
&lt;P&gt;Do you know why?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2023 13:18:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transforming-data-from-horizontal-to-vertical/m-p/895897#M353962</guid>
      <dc:creator>niki0209</dc:creator>
      <dc:date>2023-09-26T13:18:42Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming data from horizontal to vertical</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transforming-data-from-horizontal-to-vertical/m-p/895898#M353963</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/302884"&gt;@niki0209&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi. Thanks for trying to help, but it doesn't seem to work.&lt;/P&gt;
&lt;P&gt;(Yes, I am working with a proper SAS dataset - I just made up some variables names quickly).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I use the code it just gives me an empty data set.&lt;/P&gt;
&lt;P&gt;Do you know why?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Something about your actual real SAS data set is different than the one you showed. Please provide the data as working SAS data step code, as I explained earlier. Also please show the EXACT code you used.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2023 13:26:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transforming-data-from-horizontal-to-vertical/m-p/895898#M353963</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-09-26T13:26:44Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming data from horizontal to vertical</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transforming-data-from-horizontal-to-vertical/m-p/895899#M353964</link>
      <description>Dude, this code is perfect. Thank you very much! (I don't actually have commas in my variable names, but I get your point ;-). )</description>
      <pubDate>Tue, 26 Sep 2023 13:26:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transforming-data-from-horizontal-to-vertical/m-p/895899#M353964</guid>
      <dc:creator>niki0209</dc:creator>
      <dc:date>2023-09-26T13:26:14Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming data from horizontal to vertical</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transforming-data-from-horizontal-to-vertical/m-p/895911#M353973</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/302884"&gt;@niki0209&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi. Thanks for trying to help, but it doesn't seem to work.&lt;/P&gt;
&lt;P&gt;(Yes, I am working with a proper SAS dataset - I just made up some variables names quickly).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I use the code it just gives me an empty data set.&lt;/P&gt;
&lt;P&gt;Do you know why?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;We might have a chance of answering that if you include the log with the code an all of the notes from running the code. Copy the entire log text, on the forum open a text box using the &amp;lt;/&amp;gt; icon that appears above the message window and paste all of the copied text.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2023 14:56:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transforming-data-from-horizontal-to-vertical/m-p/895911#M353973</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-09-26T14:56:09Z</dc:date>
    </item>
    <item>
      <title>Re: Transforming data from horizontal to vertical</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transforming-data-from-horizontal-to-vertical/m-p/956869#M373581</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;, many thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2025 12:01:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transforming-data-from-horizontal-to-vertical/m-p/956869#M373581</guid>
      <dc:creator>DrAbhijeetSafai</dc:creator>
      <dc:date>2025-01-22T12:01:44Z</dc:date>
    </item>
  </channel>
</rss>

