<?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: Help with restructuring a data set  using a Data Step to create a new dataset in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/SAS-class-R/m-p/699980#M25666</link>
    <description>&lt;P&gt;What is wrong with using a proper tool like Proc Transpose?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you have errors it is best practice to copy the log information with the entire data step or procedure code and all notes, warnings and errors. Paste the copied text into a code box opened on the forum with the &amp;lt;/&amp;gt; icon to preserve formatting and appearance of the diagnostics that SAS often supplies with errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are referencing 4 variables that do not exist in your data: yr2009, yr2010 etc. So they have no values.&lt;/P&gt;
&lt;P&gt;Your variable HtFt is never text and has values like 15, 16, 20, not 2009, 2010, 2011 or 2012. So you are 1) going to get conversion messages in the log and 2) none of the comparisons will ever be true so all of your _2009 etc variables will always be missing.&lt;/P&gt;</description>
    <pubDate>Wed, 18 Nov 2020 20:25:57 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-11-18T20:25:57Z</dc:date>
    <item>
      <title>SAS class R</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-class-R/m-p/699969#M25664</link>
      <description>&lt;PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Jan 2021 13:37:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-class-R/m-p/699969#M25664</guid>
      <dc:creator>RuthE</dc:creator>
      <dc:date>2021-01-26T13:37:00Z</dc:date>
    </item>
    <item>
      <title>Re: Help with restructuring a data set  using a Data Step to create a new dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-class-R/m-p/699975#M25665</link>
      <description>&lt;P&gt;It can be done much simpler with an array using the years of interest as indexes&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TreesWide2;
   set Trees;
   array _ {2009 : 2012} _2009 - _2012;
   do until (last.Type);
      set Trees;
      by Type;
      _ [Year] = HtFt;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Type   Year  HtFt _2009 _2010 _2011 _2012 
Aspen  2010  16    15   16    .     . 
Maple  2012  10    .    6     8     10 
Spruce 2012  25    22   23    24    25 &lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Nov 2020 20:02:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-class-R/m-p/699975#M25665</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-18T20:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: Help with restructuring a data set  using a Data Step to create a new dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-class-R/m-p/699980#M25666</link>
      <description>&lt;P&gt;What is wrong with using a proper tool like Proc Transpose?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you have errors it is best practice to copy the log information with the entire data step or procedure code and all notes, warnings and errors. Paste the copied text into a code box opened on the forum with the &amp;lt;/&amp;gt; icon to preserve formatting and appearance of the diagnostics that SAS often supplies with errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are referencing 4 variables that do not exist in your data: yr2009, yr2010 etc. So they have no values.&lt;/P&gt;
&lt;P&gt;Your variable HtFt is never text and has values like 15, 16, 20, not 2009, 2010, 2011 or 2012. So you are 1) going to get conversion messages in the log and 2) none of the comparisons will ever be true so all of your _2009 etc variables will always be missing.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 20:25:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-class-R/m-p/699980#M25666</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-11-18T20:25:57Z</dc:date>
    </item>
    <item>
      <title>Re: Help with restructuring a data set  using a Data Step to create a new dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-class-R/m-p/701435#M25768</link>
      <description>&lt;P&gt;Instead of using an array, you could also edit your DATA step to use the following&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF&amp;nbsp; Year = '2009' THEN Yr2009 = HtFt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 15:15:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-class-R/m-p/701435#M25768</guid>
      <dc:creator>tmlee02</dc:creator>
      <dc:date>2020-12-10T15:15:56Z</dc:date>
    </item>
    <item>
      <title>Re: Help with restructuring a data set  using a Data Step to create a new dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-class-R/m-p/702442#M25913</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/344793"&gt;@RuthE&lt;/a&gt;&amp;nbsp;Did this solve your problem?&lt;/P&gt;</description>
      <pubDate>Mon, 30 Nov 2020 09:41:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-class-R/m-p/702442#M25913</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-30T09:41:32Z</dc:date>
    </item>
    <item>
      <title>Re: Help with restructuring a data set  using a Data Step to create a new dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-class-R/m-p/705842#M26280</link>
      <description>&lt;P&gt;Hi Ruth,&lt;BR /&gt;&lt;BR /&gt;I am not sure if you have found the solution already. The below code runs fine for me:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA	WORK.TreesWide2;
	SET	Work.Trees ;
	BY	Type;

	RETAIN	_2009 _2010 _2011 _2012;

	IF	FIRST.Type = 1	THEN	CALL MISSING (_2009, _2010, _2011 , _2012);
	IF			Year = '2009' THEN _2009 = HtFt;
		ELSE IF Year = '2010' THEN _2010 = HtFt;
		ELSE IF Year = '2011' THEN _2011 = HtFt;
		ELSE IF Year = '2012' THEN _2012 = HtFt;

	IF	LAST.Type = 1;
    DROP Year HtFt;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;This generated the following wide dataset:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Type&lt;/TD&gt;&lt;TD&gt;_2009&lt;/TD&gt;&lt;TD&gt;_2010&lt;/TD&gt;&lt;TD&gt;_2011&lt;/TD&gt;&lt;TD&gt;_2012&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Aspen&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;TD&gt;16&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Maple&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Spruce&lt;/TD&gt;&lt;TD&gt;22&lt;/TD&gt;&lt;TD&gt;23&lt;/TD&gt;&lt;TD&gt;24&lt;/TD&gt;&lt;TD&gt;25&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;BR /&gt;Please let me know if this doesn't work for you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Adhuna&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2020 20:50:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-class-R/m-p/705842#M26280</guid>
      <dc:creator>adhunamukherjee</dc:creator>
      <dc:date>2020-12-14T20:50:05Z</dc:date>
    </item>
  </channel>
</rss>

