<?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 creating the wide table from narrow table with Retain statement but not able to retain the values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/creating-the-wide-table-from-narrow-table-with-Retain-statement/m-p/677936#M204573</link>
    <description>&lt;P&gt;Created the data in T1 and sorted by name variable in T2, and then wanted to create wide table with two columns Maths1 and English1. Wanted to output the when the last.name=1 so that Maths1 and English1 variable value will come in one row. But the values in PDV not retaining for variables. Please help.&lt;/P&gt;&lt;P&gt;Expected output:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Name Maths1 English1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Nikhil 45 12&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;gho 48 78&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;monu 56 43&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;sonu 54 86&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;veena 66 23&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;Program Code;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data T1;&lt;BR /&gt;infile datalines;&lt;BR /&gt;length Name Subject = $10;&lt;BR /&gt;input Name $ Subject$ Marks;&lt;BR /&gt;datalines;&lt;BR /&gt;Nikhil Maths 45&lt;BR /&gt;Nikhil English 12&lt;BR /&gt;gho Maths 48&lt;BR /&gt;gho English 78&lt;BR /&gt;veena Maths 66&lt;BR /&gt;veena English 23&lt;BR /&gt;sonu Maths 54&lt;BR /&gt;sonu English 86&lt;BR /&gt;monu Maths 56&lt;BR /&gt;monu English 43&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;Proc print data=T1;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=T1 out=T2;&lt;BR /&gt;by Name;&lt;BR /&gt;run;&lt;BR /&gt;Proc print data=T2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data T3;&lt;BR /&gt;set T2;&lt;BR /&gt;by Name;&lt;BR /&gt;retain Name Subject Marks;&lt;BR /&gt;if Subject="Maths" then&lt;BR /&gt;Maths1=Marks;&lt;BR /&gt;else if Subject="English" then&lt;BR /&gt;English1=Marks;&lt;BR /&gt;if last.name=1 then output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc print data=T3;&lt;BR /&gt;run;&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>Thu, 20 Aug 2020 03:07:14 GMT</pubDate>
    <dc:creator>Nikhilvg</dc:creator>
    <dc:date>2020-08-20T03:07:14Z</dc:date>
    <item>
      <title>creating the wide table from narrow table with Retain statement but not able to retain the values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-the-wide-table-from-narrow-table-with-Retain-statement/m-p/677936#M204573</link>
      <description>&lt;P&gt;Created the data in T1 and sorted by name variable in T2, and then wanted to create wide table with two columns Maths1 and English1. Wanted to output the when the last.name=1 so that Maths1 and English1 variable value will come in one row. But the values in PDV not retaining for variables. Please help.&lt;/P&gt;&lt;P&gt;Expected output:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Name Maths1 English1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Nikhil 45 12&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;gho 48 78&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;monu 56 43&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;sonu 54 86&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;veena 66 23&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;Program Code;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data T1;&lt;BR /&gt;infile datalines;&lt;BR /&gt;length Name Subject = $10;&lt;BR /&gt;input Name $ Subject$ Marks;&lt;BR /&gt;datalines;&lt;BR /&gt;Nikhil Maths 45&lt;BR /&gt;Nikhil English 12&lt;BR /&gt;gho Maths 48&lt;BR /&gt;gho English 78&lt;BR /&gt;veena Maths 66&lt;BR /&gt;veena English 23&lt;BR /&gt;sonu Maths 54&lt;BR /&gt;sonu English 86&lt;BR /&gt;monu Maths 56&lt;BR /&gt;monu English 43&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;Proc print data=T1;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=T1 out=T2;&lt;BR /&gt;by Name;&lt;BR /&gt;run;&lt;BR /&gt;Proc print data=T2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data T3;&lt;BR /&gt;set T2;&lt;BR /&gt;by Name;&lt;BR /&gt;retain Name Subject Marks;&lt;BR /&gt;if Subject="Maths" then&lt;BR /&gt;Maths1=Marks;&lt;BR /&gt;else if Subject="English" then&lt;BR /&gt;English1=Marks;&lt;BR /&gt;if last.name=1 then output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc print data=T3;&lt;BR /&gt;run;&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>Thu, 20 Aug 2020 03:07:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-the-wide-table-from-narrow-table-with-Retain-statement/m-p/677936#M204573</guid>
      <dc:creator>Nikhilvg</dc:creator>
      <dc:date>2020-08-20T03:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: creating the wide table from narrow table with Retain statement but not able to retain the value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-the-wide-table-from-narrow-table-with-Retain-statement/m-p/677937#M204574</link>
      <description>&lt;P&gt;You are retaining the wrong variables. You used&lt;/P&gt;
&lt;PRE&gt;retain Name Subject Marks;&lt;/PRE&gt;
&lt;P&gt;Try&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;retain maths1 english1;&lt;/PRE&gt;
&lt;P&gt;You may also want:&amp;nbsp; KEEP name maths1 english1; so those are the only values kept in the output data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you Retain a variable that is in the data set used on a SET statement the value in the data set is reset for each record read.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Aug 2020 03:13:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-the-wide-table-from-narrow-table-with-Retain-statement/m-p/677937#M204574</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-08-20T03:13:55Z</dc:date>
    </item>
  </channel>
</rss>

