<?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: change the dataset structure in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/change-the-dataset-structure/m-p/631082#M186910</link>
    <description>&lt;P&gt;Generally, this is a poor structure for most types of data, making the subsequent coding much harder; unless for some reason, you are trying to create a presentation or display. What is the goal of having such a structure?&lt;/P&gt;</description>
    <pubDate>Tue, 10 Mar 2020 20:08:03 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-03-10T20:08:03Z</dc:date>
    <item>
      <title>change the dataset structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-the-dataset-structure/m-p/631081#M186909</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a dataset one with company code and their counts for each month for last 5 months.&lt;/P&gt;&lt;P&gt;I want to get change the dataset one to have structure like dataset two. The year month in dataset one is a character column.&lt;/P&gt;&lt;P&gt;what is the best way to achieve this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;dataset one&lt;BR /&gt;Year_Mnth&amp;nbsp; comp_code&amp;nbsp; code_type&amp;nbsp; count&lt;BR /&gt;201910&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 001&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Medium&amp;nbsp;&amp;nbsp; 15&lt;BR /&gt;201911&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 001&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Medium&amp;nbsp;&amp;nbsp;&amp;nbsp; 9&lt;BR /&gt;201912&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 001&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Medium&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&lt;BR /&gt;202001&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 001&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Medium&amp;nbsp;&amp;nbsp; 18&lt;BR /&gt;202002&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 001&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Medium&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;BR /&gt;201910&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 002&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;High&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11&lt;BR /&gt;201911&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 002&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; High&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8&lt;BR /&gt;201912&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 002&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; High&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12&lt;BR /&gt;202001&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 002&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; High&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 16&lt;BR /&gt;202002&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 002&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; High&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 15&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dataset two&lt;/P&gt;&lt;P&gt;comp_code code_type mnth1 mnth2 mnth3 mnth4 mnth5&lt;BR /&gt;001&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Medium&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 15&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 18&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;BR /&gt;002&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; High&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 16&amp;nbsp;&amp;nbsp;&amp;nbsp; 15&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Nick&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 20:04:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-the-dataset-structure/m-p/631081#M186909</guid>
      <dc:creator>nickspencer</dc:creator>
      <dc:date>2020-03-10T20:04:41Z</dc:date>
    </item>
    <item>
      <title>Re: change the dataset structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-the-dataset-structure/m-p/631082#M186910</link>
      <description>&lt;P&gt;Generally, this is a poor structure for most types of data, making the subsequent coding much harder; unless for some reason, you are trying to create a presentation or display. What is the goal of having such a structure?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 20:08:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-the-dataset-structure/m-p/631082#M186910</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-03-10T20:08:03Z</dc:date>
    </item>
    <item>
      <title>Re: change the dataset structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-the-dataset-structure/m-p/631084#M186912</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/206798"&gt;@nickspencer&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input (Year_Mnth  comp_code  code_type) ($)  count;
cards;
201910        001                Medium   15
201911        001                Medium    9
201912        001                Medium    6
202001        001                Medium   18
202002        001                Medium    3
201910        002                 High        11
201911        002       High      8
201912        002       High     12
202001        002       High     16
202002        002       High     15
;

proc transpose data=have out=want(drop=_:) prefix=mnth;
by comp_code code_type;
var count;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Mar 2020 20:10:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-the-dataset-structure/m-p/631084#M186912</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-10T20:10:35Z</dc:date>
    </item>
    <item>
      <title>Re: change the dataset structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-the-dataset-structure/m-p/631088#M186914</link>
      <description>&lt;P&gt;hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;How can I sort that date values in ascending or descending order? It is in character datatype in the source.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 20:17:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-the-dataset-structure/m-p/631088#M186914</guid>
      <dc:creator>nickspencer</dc:creator>
      <dc:date>2020-03-10T20:17:03Z</dc:date>
    </item>
    <item>
      <title>Re: change the dataset structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-the-dataset-structure/m-p/631089#M186915</link>
      <description>&lt;P&gt;which one is in chartype?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 20:17:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-the-dataset-structure/m-p/631089#M186915</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-10T20:17:47Z</dc:date>
    </item>
    <item>
      <title>Re: change the dataset structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-the-dataset-structure/m-p/631093#M186916</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;year_mnth is character type. And it is not sorted in the original dataset to have mnth1, mnth2...&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 20:31:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-the-dataset-structure/m-p/631093#M186916</guid>
      <dc:creator>nickspencer</dc:creator>
      <dc:date>2020-03-10T20:31:01Z</dc:date>
    </item>
    <item>
      <title>Re: change the dataset structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-the-dataset-structure/m-p/631095#M186917</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/206798"&gt;@nickspencer&lt;/a&gt;&amp;nbsp; How about?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
 set have;
 _temp_yr_mnth=input(Year_Mnth,yymmn6.);
run;

proc sort data=temp ;
by comp_code  code_type _temp_yr_mnth;
run;
/*And then the transpose using TEMP sorted as source*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Plus, the numeric variable is better as you can comfortably use for calculating any time series related problems&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 20:36:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-the-dataset-structure/m-p/631095#M186917</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-10T20:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: change the dataset structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-the-dataset-structure/m-p/631096#M186918</link>
      <description>Doesn't matter, it'll sort correctly with a standard PROC SORT.</description>
      <pubDate>Tue, 10 Mar 2020 20:34:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-the-dataset-structure/m-p/631096#M186918</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-03-10T20:34:51Z</dc:date>
    </item>
    <item>
      <title>Re: change the dataset structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-the-dataset-structure/m-p/631113#M186926</link>
      <description>&lt;P&gt;ONE example of why you may want to consider have date values stored as SAS dates: Note that by changing the Format for the date valued Year_month you can create different summary reports. This is also a reason NOT to create a wide data set. To create a summary report for calendar quarter or year total will require reprocessing your data. And if you keep the data in a wide format the code to reprocess that will change every time a month is added to your data. The reports I have below will adjust with no additional coding if additional rows are added. As well as taking into account when someone decides to add a "Low" code type, or new Comp_code values.&lt;/P&gt;
&lt;PRE&gt;data have;
input Year_Mnth :yymmn6. comp_code $3.   code_type $  count;
cards;
201910 001 Medium 15
201911 001 Medium 9
201912 001 Medium  6
202001 001 Medium 18
202002 001 Medium  3
201910 002 High   11
201911 002 High   8
201912 002 High   12
202001 002 High   16
202002 002 High   15
;

proc tabulate data=have;
   class year_mnth comp_code code_type;
   format Year_Mnth yymmn6.;
   var count;
   table comp_code*code_type,
         year_mnth='Month' * count
         /misstext=' '
   ;

run;

proc tabulate data=have;
   class year_mnth comp_code code_type;
   format Year_Mnth yyQ6.;
   var count;
   table comp_code*code_type,
         year_mnth='Quarter' * count
         /misstext=' '
   ;
run;

proc tabulate data=have;
   class year_mnth comp_code code_type;
   format Year_Mnth year4.;
   var count;
   table comp_code*code_type,
         year_mnth='Year' * count
         /misstext=' '
   ;
run;&lt;/PRE&gt;
&lt;P&gt;If the purpose of the wide data is to create a report that people read, don't do it. Use the report procedure tools to create the columns based on the values of the date variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 21:33:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-the-dataset-structure/m-p/631113#M186926</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-10T21:33:27Z</dc:date>
    </item>
    <item>
      <title>Re: change the dataset structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-the-dataset-structure/m-p/631135#M186945</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; This is helpful. What if I have dataset with full date and want to calculate the count for each month year?</description>
      <pubDate>Wed, 11 Mar 2020 00:43:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-the-dataset-structure/m-p/631135#M186945</guid>
      <dc:creator>nickspencer</dc:creator>
      <dc:date>2020-03-11T00:43:01Z</dc:date>
    </item>
    <item>
      <title>Re: change the dataset structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-the-dataset-structure/m-p/631145#M186953</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt; proc transpose works perfectly for me. I tried to use the statement ID year_mnth. This works great for me since it will work if any dates are missing. But when I use the ID and prefix it gets column name with prefix + ID .&lt;BR /&gt;Is there a way to still name them mnth1, mnth2 , mnth3...using ID statement?</description>
      <pubDate>Wed, 11 Mar 2020 02:13:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-the-dataset-structure/m-p/631145#M186953</guid>
      <dc:creator>nickspencer</dc:creator>
      <dc:date>2020-03-11T02:13:17Z</dc:date>
    </item>
    <item>
      <title>Re: change the dataset structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-the-dataset-structure/m-p/631146#M186954</link>
      <description>Have you tried adding Yrmonth or a month variable to the ID statement?</description>
      <pubDate>Wed, 11 Mar 2020 02:19:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-the-dataset-structure/m-p/631146#M186954</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-03-11T02:19:51Z</dc:date>
    </item>
    <item>
      <title>Re: change the dataset structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-the-dataset-structure/m-p/631148#M186956</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/206798"&gt;@nickspencer&lt;/a&gt;&amp;nbsp; If you intend to use ID variable, the values of ID variable would become your transposed variable names. So expecting the transposed variables as &lt;STRONG&gt;Month1----MonthN&lt;/STRONG&gt; is not viable. This is something you have to think about and decide what is desired as final. Please let us know.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Mar 2020 02:53:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-the-dataset-structure/m-p/631148#M186956</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-11T02:53:55Z</dc:date>
    </item>
  </channel>
</rss>

