<?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 place your values as horizontal columns? in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734203#M38553</link>
    <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;. Thank you. It seems like it worked, however its a report and I cant do anything with it after it. I want it to be a dataset so I can query with it.&lt;BR /&gt;&lt;BR /&gt;With regarding to your note on preparing data step myself. I tried to do that I even followed the blog of Jedi SAS Tricks but I could not figure out how it works.</description>
    <pubDate>Thu, 15 Apr 2021 11:49:28 GMT</pubDate>
    <dc:creator>Andalusia</dc:creator>
    <dc:date>2021-04-15T11:49:28Z</dc:date>
    <item>
      <title>How to place your values as horizontal columns?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734145#M38547</link>
      <description>&lt;P&gt;note: Im using SAS EG version 7.15&lt;BR /&gt;&lt;BR /&gt;I have a dataset which looks like below(please note that in reality its much bigger!).&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;(char)  (num)&amp;nbsp; &amp;nbsp;  (char)&lt;BR /&gt;type&amp;nbsp; &amp;nbsp; &amp;nbsp;quarter&amp;nbsp; &amp;nbsp;phase&lt;BR /&gt;K-11&amp;nbsp; &amp;nbsp; &amp;nbsp;202001&amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;K-11&amp;nbsp; &amp;nbsp; &amp;nbsp;202101&amp;nbsp; &amp;nbsp; 2&lt;BR /&gt;K-11&amp;nbsp; &amp;nbsp; &amp;nbsp;202003&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;BR /&gt;K-12&amp;nbsp; &amp;nbsp; &amp;nbsp;202101&amp;nbsp; &amp;nbsp; 3&lt;BR /&gt;K-12&amp;nbsp; &amp;nbsp; &amp;nbsp;202102&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;BR /&gt;K-12&amp;nbsp; &amp;nbsp; &amp;nbsp;202002&amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;K-13&amp;nbsp; &amp;nbsp; &amp;nbsp;202002&amp;nbsp; &amp;nbsp; 2&lt;BR /&gt;K-13&amp;nbsp; &amp;nbsp; &amp;nbsp;202103&amp;nbsp; &amp;nbsp; 3&lt;BR /&gt;K-13&amp;nbsp; &amp;nbsp; &amp;nbsp;202104&amp;nbsp; &amp;nbsp; 2&lt;/PRE&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;I want to achieve the following:&lt;BR /&gt;1. I want to place the values of &lt;STRONG&gt;quarters&lt;/STRONG&gt;&amp;nbsp;as horizontal columns and fill their values with the values of &lt;STRONG&gt;phase&lt;/STRONG&gt;. So my desired output would be this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;type&amp;nbsp; &amp;nbsp; 202001 202002 202003 202004 202101 202102 202103 202104
K-11&amp;nbsp; &amp;nbsp;  1                          2       
K-12&amp;nbsp; &amp;nbsp;         1                   3 
K-13&amp;nbsp; &amp;nbsp;         2                                  3       2&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Apr 2021 08:54:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734145#M38547</guid>
      <dc:creator>Andalusia</dc:creator>
      <dc:date>2021-04-15T08:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to place your values as horizontal columns?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734147#M38548</link>
      <description>&lt;P&gt;PROC REPORT does this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input type $ quarter :yymmn6. phase;
format quarter yymmn6.;
datalines;
K-11     202001    1
K-11     202101    2
K-11     202003           
K-12     202101    3
K-12     202102           
K-12     202002    1
K-13     202002    2
K-13     202103    3
K-13     202104    2
;

proc report data=have;
column type phase,quarter;
define type / group;
define phase / "" analysis;
define quarter / "" across order=formatted;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Apr 2021 09:02:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734147#M38548</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-15T09:02:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to place your values as horizontal columns?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734191#M38550</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried your snippet on my data set and I got this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;ERROR: phase is an ANALYSIS variable but not numeric.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE REPORT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Apr 2021 11:10:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734191#M38550</guid>
      <dc:creator>Andalusia</dc:creator>
      <dc:date>2021-04-15T11:10:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to place your values as horizontal columns?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734200#M38552</link>
      <description>&lt;P&gt;Then we need to add a little twist to the REPORT procedure:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines truncover;
input type $ quarter :yymmn6. phase $;
format quarter yymmn6.;
datalines;
K-11     202001    1
K-11     202101    2
K-11     202003           
K-12     202101    3
K-12     202102           
K-12     202002    1
K-13     202002    2
K-13     202103    3
K-13     202104    2
;

proc report data=have;
column type phase,quarter n;
define type / group;
define phase / "" display;
define quarter / "" across order=formatted;
define n / noprint;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;By posting your data as a data step yourself, you prevent us from making mistakes with regards to the recreation of your data.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Apr 2021 11:36:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734200#M38552</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-15T11:36:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to place your values as horizontal columns?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734203#M38553</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;. Thank you. It seems like it worked, however its a report and I cant do anything with it after it. I want it to be a dataset so I can query with it.&lt;BR /&gt;&lt;BR /&gt;With regarding to your note on preparing data step myself. I tried to do that I even followed the blog of Jedi SAS Tricks but I could not figure out how it works.</description>
      <pubDate>Thu, 15 Apr 2021 11:49:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734203#M38553</guid>
      <dc:creator>Andalusia</dc:creator>
      <dc:date>2021-04-15T11:49:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to place your values as horizontal columns?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734209#M38554</link>
      <description>&lt;P&gt;A structure like you showed is typical for reports, for datasets it is very unfavorable, as it makes further coding harder.&lt;/P&gt;
&lt;P&gt;Maxim 19: Long Beats Wide.&lt;/P&gt;
&lt;P&gt;So what do you want to do with your data further on?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Look at my two DATALINES examples, they contain character, numeric and date values. Most of what you need to know to prepare simple datasets yourself.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Apr 2021 12:25:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734209#M38554</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-15T12:25:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to place your values as horizontal columns?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734210#M38555</link>
      <description>&lt;P&gt;This the transpose code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose
  data=have
  out=want (drop=_name_)
  prefix=q_
;
by type;
var phase;
id quarter;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Apr 2021 12:27:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734210#M38555</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-15T12:27:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to place your values as horizontal columns?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734216#M38556</link>
      <description>&lt;PRE&gt;data have;
infile datalines truncover;
input type $ quarter :yymmn6. phase $;
format quarter yymmn6.;
datalines;
K-11     202001    1
K-11     202101    2
K-11     202003           
K-12     202101    3
K-12     202102           
K-12     202002    1
K-13     202002    2
K-13     202103    3
K-13     202104    2
;
proc transpose data=have out=want ;
by type;
var phase;
id quarter;
idlabel quarter;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Apr 2021 12:34:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734216#M38556</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-04-15T12:34:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to place your values as horizontal columns?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734232#M38557</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;I ran your &lt;STRONG&gt;transpose&lt;/STRONG&gt; snippet and received:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ERROR: The ID value "K-11" occurs twice in the same BY group.
ERROR: Too many bad BY groups.&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want further with my data: I want to calculate the difference between the last quarter and the second last quarter and place that in a new column. After that I wan that dataset to be a LASR table to create some graphs with it.&lt;BR /&gt;&lt;BR /&gt;With regards to your two DATALINES. I will use that as a reference for future questions. Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Apr 2021 12:35:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734232#M38557</guid>
      <dc:creator>Andalusia</dc:creator>
      <dc:date>2021-04-15T12:35:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to place your values as horizontal columns?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734234#M38558</link>
      <description>I received the same output I received when I ran &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;'s transpose snippet&lt;BR /&gt;&lt;BR /&gt;ERROR: The ID value "K-11" occurs twice in the same BY group.&lt;BR /&gt;ERROR: Too many bad BY groups.</description>
      <pubDate>Thu, 15 Apr 2021 12:37:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734234#M38558</guid>
      <dc:creator>Andalusia</dc:creator>
      <dc:date>2021-04-15T12:37:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to place your values as horizontal columns?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734251#M38559</link>
      <description>&lt;P&gt;You must have data like this :&lt;/P&gt;
&lt;PRE&gt;K-11     202001    1
K-11     202101    2&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;K-11     202101   22&lt;/STRONG&gt;&lt;/FONT&gt;
K-11     202003           
K-12     202101    3
K-12     202102           
K-12     202002    1
K-13     202002    2
K-13     202103    3
K-13     202104    2&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;You need figure out what output you want to see for this data.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Apr 2021 12:50:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734251#M38559</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-04-15T12:50:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to place your values as horizontal columns?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734258#M38560</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/358343"&gt;@Andalusia&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;I ran your &lt;STRONG&gt;transpose&lt;/STRONG&gt; snippet and received:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ERROR: The ID value "K-11" occurs twice in the same BY group.
ERROR: Too many bad BY groups.&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I want further with my data: I want to calculate the difference between the last quarter and the second last quarter and place that in a new column. After that I wan that dataset to be a LASR table to create some graphs with it.&lt;BR /&gt;&lt;BR /&gt;With regards to your two DATALINES. I will use that as a reference for future questions. Thank you.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Cannot happen with the data you posted:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines truncover;
input type $ quarter :yymmn6. phase $;
format quarter yymmn6.;
datalines;
K-11     202001    1
K-11     202101    2
K-11     202003           
K-12     202101    3
K-12     202102           
K-12     202002    1
K-13     202002    2
K-13     202103    3
K-13     202104    2
;

proc transpose
  data=have
  out=want (drop=_name_)
  prefix=q_
;
by type;
var phase;
id quarter;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt; 73         data have;
 74         infile datalines truncover;
 75         input type $ quarter :yymmn6. phase $;
 76         format quarter yymmn6.;
 77         datalines;
 
 NOTE: The data set WORK.HAVE has 9 observations and 3 variables.
 NOTE:  Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 87         ;
 88         
 89         proc transpose
 90           data=have
 91           out=want (drop=_name_)
 92           prefix=q_
 93         ;
 94         by type;
 95         var phase;
 96         id quarter;
 97         run;
 
 NOTE: There were 9 observations read from the data set WORK.HAVE.
 NOTE: The data set WORK.WANT has 3 observations and 8 variables.
 NOTE:  Verwendet wurde: PROZEDUR TRANSPOSE - (Gesamtverarbeitungszeit):
       real time           0.00 seconds
       cpu time            0.02 seconds&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;And you &lt;STRONG&gt;POSITIVELY&lt;/STRONG&gt; do &lt;STRONG&gt;NOT&lt;/STRONG&gt; need to transpose. You can easily compare values across observations by using a RETAINed variable, or by joining the dataset with itself. This is all much easier done with a vertical dataset.&lt;/P&gt;
&lt;P&gt;What "difference" do you want to calculate? phase is character in your dataset, so it's not suited for calculations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please post a comprehensive example of your dataset (containing "edge cases") in usable form, and the expected outcome.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Apr 2021 12:51:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734258#M38560</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-15T12:51:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to place your values as horizontal columns?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734265#M38561</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;Oke I tried to give you a&amp;nbsp;&lt;SPAN&gt;comprehensive example of my dataset (containing "edge cases").&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have;
infile datalines truncover;
input type $ quarter phase $;
datalines;
K-11 202001 1
K-11 202101 2
K-11 202003
K-12 202101 3
K-12 202102 1
K-12 202002 1
K-13 202002 2
K-13 202103 3
K-13 202104 2
;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;My quarter column is just a numeric, that needs to stay like that. Oké below is what I want as a dataset (not a report!):&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;type&amp;nbsp; &amp;nbsp; 202001 202002 202003 202004 202101 202102 202103 202104  diff_phase 
K-11&amp;nbsp; &amp;nbsp;  1                          2                             1        
K-12&amp;nbsp; &amp;nbsp;         1                   3      1                      -2 
K-13&amp;nbsp; &amp;nbsp;         2                                  3      2       -1 &lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;I want all the columns above so I guess a transpose is necessary?. In &lt;STRONG&gt;diff_phase&lt;/STRONG&gt; I calculate the difference between the last &lt;STRONG&gt;quarter&lt;/STRONG&gt; and the second last &lt;STRONG&gt;quarter&lt;/STRONG&gt; for every type.&lt;EM&gt;(So 2-1 for K-11, 1-3 for K-12 and 2-3 for K-13)&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;Really glad&amp;nbsp;if you could help me solve this problem &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Apr 2021 13:24:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734265#M38561</guid>
      <dc:creator>Andalusia</dc:creator>
      <dc:date>2021-04-15T13:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to place your values as horizontal columns?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734271#M38562</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;. Read my new post under &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;'s last post. I've posted a new dataset.&lt;BR /&gt;</description>
      <pubDate>Thu, 15 Apr 2021 13:16:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734271#M38562</guid>
      <dc:creator>Andalusia</dc:creator>
      <dc:date>2021-04-15T13:16:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to place your values as horizontal columns?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734315#M38567</link>
      <description>&lt;P&gt;Sorry, but your dataset is simply dumb.&lt;/P&gt;
&lt;P&gt;Storing a number which you need for calculation as character is stupidity #1. Numbers are numbers are numbers, and if you want to make a calculation from them, you STORE THEM THAT WAY, period.&lt;/P&gt;
&lt;P&gt;Second, a date-related values HAS TO BE STORED AS SUCH in SAS, otherwise you deprive yourself completely of using all the nice tools SAS provides for dealing with such values. A SAS date value is numeric, contains a count of days starting at 1960-01-01, and has a date format attached.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the intended result:&lt;/P&gt;
&lt;P&gt;A wide layout is needed for two reasons: running a regression (or similar) analysis that needs lots of categorical values in one observation, or as a report for human consumption. For anything you want to use in further data processing, you use a long layout.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The phase differences are calculated like that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines truncover;
input type $ quarter :yyq6. phase;
format quarter yyqn6.;
datalines;
K-11 2020Q01 1
K-11 2021Q01 2
K-11 2020Q03
K-12 2021Q01 3
K-12 2021Q02 1
K-12 2020Q02 1
K-13 2020Q02 2
K-13 2021Q03 3
K-13 2021Q04 2
;

proc sort data=have;
by type quarter;
run;

data want;
set have;
where phase ne .;
by type;
retain diff_phase;
if first.type then diff_phase = phase;
if last.type
then do;
  diff_phase = phase - diff_phase;
  output;
end;
diff_phase = phase;
keep type diff_phase;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To create the wide dataset, you need this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select min(quarter), max(quarter) into :minq, :maxq from have;
quit;

data template;
quarter = &amp;amp;minq.;
do until (quarter gt &amp;amp;maxq.);
  output;
  quarter = intnx('quarter',quarter,1);
end;
run;

data long;
set
  template
  have
;
run;

proc transpose
  data=long
  out=wide (
    drop=_name_
    where=(type ne "")
  )
  prefix=q_
;
by type;
var phase;
id quarter;
run;

data want_wide;
merge
  wide
  want
;
by type;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The template is needed to create the order of columns for the tranpose.&lt;/P&gt;
&lt;P&gt;All this is done easier in PROC REPORT:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data pre_report / view=pre_report;
merge
  have
  want
;
by type;
run;

proc report data=pre_report;
column type phase,quarter diff_phase;
define type / group;
define phase / "" analysis;
define quarter / "" across order=formatted;
define diff_phase / group;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Apr 2021 15:15:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734315#M38567</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-15T15:15:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to place your values as horizontal columns?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734607#M38568</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp; This is a quiet complex situation, I dont know what is going wrong in my code. Can you see it? Also I can see that you changed the datelines and added the Q in it. I cannot do that and I also don't want to change my source data.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;This is my code:&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=work.filtered_main_dataset;
by type quarter;
run;

data want;
set work.filtered_main_dataset;
where c_phase ne .;
by type;
retain diff_phase;
if first.type then diff_phase = c_phase;
if last.type
then do;
  diff_phase = c_phase - diff_phase;
  output;
end;
diff_phase = c_phase;
keep type diff_phase;
run;

data long;
set
  work.filtered_main_dataset
;
run;

proc transpose
  data=long
  out=wide (
    drop=_name_
    where=(type ne "")
  )
  prefix=q_
;
by type;
var c_phase;
id quarter;
run;

data want_wide;
merge
  wide
  want
;
by type;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;This is my log:&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;2 The SAS System 23:15 Thursday, April 15, 2021
44
45 data long;
46 set
47 work.filtered_main_dataset
48 ;
49 run;

NOTE: There were 7238 observations read from the data set WORK.FILTERED_MAIN_DATASET.
NOTE: The data set WORK.LONG has 7238 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

50
51 proc transpose
52 data=long
53 out=wide (
54 drop=_name_
55 where=(type ne "")
56 )
57 prefix=q_
58 ;
59 by type;
60 var c_phase;
61 id quarter;
62 run;

ERROR: The ID value "q_201904" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
type=TWK-B013
ERROR: The ID value "q_201902" occurs twice in the same BY group.
ERROR: The ID value "q_201904" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
type=TWK-B014
ERROR: The ID value "q_201904" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
type=TWK-B017
ERROR: The ID value "q_201904" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
type=TWK-B020
ERROR: The ID value "q_201904" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
type=TWK-B022
ERROR: The ID value "q_202004" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
type=TWK-B025
ERROR: The ID value "q_202004" occurs twice in the same BY group.
ERROR: The ID value "q_202004" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
type=TWK-B028
ERROR: The ID value "q_201904" occurs twice in the same BY group.
ERROR: The ID value "q_202004" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
type=TWK-B030
ERROR: The ID value "q_201904" occurs twice in the same BY group.
3 The SAS System 23:15 Thursday, April 15, 2021

NOTE: The above message was for the following BY group:
type=TWK-B035
ERROR: The ID value "q_202001" occurs twice in the same BY group.
NOTE: The above message was for the following BY group:
type=TWK-B037
ERROR: The ID value "q_201903" occurs twice in the same BY group.
ERROR: Too many bad BY groups.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 269 observations read from the data set WORK.LONG.
WARNING: The data set WORK.WIDE may be incomplete. When this step was stopped there were 0 observations and 0 variables.
WARNING: Data set WORK.WIDE was not replaced because this step was stopped.
NOTE: PROCEDURE TRANSPOSE used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

63


64 data want_wide;
65 merge
66 wide
67 want
68 ;
69 by type;
70 run;

WARNING: Multiple lengths were specified for the BY variable type by input data sets. This might cause unexpected results.
NOTE: There were 3 observations read from the data set WORK.WIDE.
NOTE: There were 988 observations read from the data set WORK.WANT.
NOTE: The data set WORK.WANT_WIDE has 991 observations and 12 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

71
72
73
74
75 GOPTIONS NOACCESSIBLE;
76 %LET _CLIENTTASKLABEL=;
77 %LET _CLIENTPROCESSFLOWNAME=;
78 %LET _CLIENTPROJECTPATH=;
79 %LET _CLIENTPROJECTPATHHOST=;
80 %LET _CLIENTPROJECTNAME=;
81 %LET _SASPROGRAMFILE=;
82 %LET _SASPROGRAMFILEHOST=;
83
84 ;*';*";*/;quit;run;
85 ODS _ALL_ CLOSE;
86
87
88 QUIT; RUN;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;This is how the first 28 rows of my filtered_main_dataset looks like:&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Andalusia_0-1618526451509.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/58090iC99062A2384F554A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Andalusia_0-1618526451509.png" alt="Andalusia_0-1618526451509.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Apr 2021 22:46:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734607#M38568</guid>
      <dc:creator>Andalusia</dc:creator>
      <dc:date>2021-04-15T22:46:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to place your values as horizontal columns?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734699#M38570</link>
      <description>&lt;P&gt;Let's begin at the start: how do you receive your data? It may be that the unfavorable data types are the consequence of an ill-designed import process.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next, there is no reason to continue working with dumb data if you receive it as such. While you process the data in SAS, you always strive for the most easy to handle form, which means treating dates/times as such and so on. If you need to re-export processed data to the source, you can always convert to the original data types then, but you do not make your own life harder just because someone else is a masochist. Or an idiot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next, implement Maxim 3 (Know Your Data). You have values for type that have more than one entry for a given quarter. Before being able to transpose/report on such data, you need to decide how to handle these multiple entries (select min, max, sum or average).&lt;/P&gt;</description>
      <pubDate>Fri, 16 Apr 2021 11:27:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734699#M38570</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-16T11:27:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to place your values as horizontal columns?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734822#M38571</link>
      <description>&lt;P&gt;Im getting this data from an external data source. Oke to solve my problem I think I need to change my quarter data to your quarter data(with that Q). How can that be done easily then?&lt;BR /&gt;&lt;BR /&gt;With regards to your Maxim 3. I want to take jus the last quarter if that quarter occurs more then once in a type. How can I achieve that?&lt;/P&gt;</description>
      <pubDate>Fri, 16 Apr 2021 22:05:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734822#M38571</guid>
      <dc:creator>Andalusia</dc:creator>
      <dc:date>2021-04-16T22:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to place your values as horizontal columns?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734859#M38574</link>
      <description>&lt;P&gt;In which firm does the data arrive? Direct unload from a DBMS, text file, Excel?&lt;/P&gt;
&lt;P&gt;This will determine where you make the conversion to proper variable types and values.&lt;/P&gt;
&lt;P&gt;Show the code you use to get the data into SAS.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Apr 2021 05:50:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/734859#M38574</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-17T05:50:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to place your values as horizontal columns?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/735172#M38577</link>
      <description>&lt;P&gt;Its a LASR Table, but the real root of the data are from a DBMS. By the way.&amp;nbsp;&lt;SPAN&gt;With regards to your Maxim 3. I want to take jus the last quarter if that quarter occurs more then once in a type. How can I achieve that?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Apr 2021 06:33:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-place-your-values-as-horizontal-columns/m-p/735172#M38577</guid>
      <dc:creator>Andalusia</dc:creator>
      <dc:date>2021-04-19T06:33:38Z</dc:date>
    </item>
  </channel>
</rss>

