<?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: Creating variables from existing variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-variables-from-existing-variables/m-p/510174#M137281</link>
    <description>&lt;P&gt;You just need to read the name value into a dummy column and then save it into the real Name variable when it is not empty. Use RETAIN the carry the old values of NAME forward.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is sketch of what you need to do.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input dummy $ 1-15 ...... ;
name=coalescec(dummy,name);
retain name;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 03 Nov 2018 15:06:19 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-11-03T15:06:19Z</dc:date>
    <item>
      <title>Creating variables from existing variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-variables-from-existing-variables/m-p/510163#M137275</link>
      <description>&lt;P&gt;Greetings all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following data set stored as a .txt file. How can I&amp;nbsp;use only one DATA step to produce an output&amp;nbsp;that only contains one observation for each variable? My ultimate goal is to have the output as the attached picture. I know I am currently missing a few other variables, but how can I create those variables from the existing ones? This is what I have so far.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data testing;&lt;BR /&gt;infile datalines firstobs=2;&lt;BR /&gt;input name $ 1-15 latest_sales_date:date11. person_total_sales 28-32;&lt;BR /&gt;format date date11.;&lt;BR /&gt;datalines;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;1234567890123456789012345678901234567890&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;David Wong&amp;nbsp; &amp;nbsp; &amp;nbsp;1/Aug/2018&amp;nbsp; 13200 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Brian Leung&amp;nbsp; &amp;nbsp; 15/Sep/2018 23450&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10/Sep/2018 33000&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Mary Chan&amp;nbsp; &amp;nbsp; &amp;nbsp; 3/Jul/2018&amp;nbsp; 45600&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20/Aug/2018 37800&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1/Sep/2018&amp;nbsp; 21500&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;30/Aug/2018 42000&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;John Tam&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12/Sep/2018 35000&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Capture.PNG" style="width: 535px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/24624i6863A232A6EA11DC/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&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>Sat, 03 Nov 2018 14:18:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-variables-from-existing-variables/m-p/510163#M137275</guid>
      <dc:creator>blowsnow__</dc:creator>
      <dc:date>2018-11-03T14:18:48Z</dc:date>
    </item>
    <item>
      <title>Re: Creating variables from existing variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-variables-from-existing-variables/m-p/510165#M137276</link>
      <description>&lt;P&gt;given your sample data&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/244119"&gt;@blowsnow__&lt;/a&gt; this should work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data testing;
infile datalines firstobs=2;
input name $ 1-15 latest_sales_date date11. person_total_sales 28-32;
format latest_sales_date date11.;
/*1234567890123456789012345678901234567890*/
datalines;

David Wong     1/Aug/2018  13200 
Brian Leung    15/Sep/2018 23450
               10/Sep/2018 33000
Mary Chan      3/Jul/2018  45600
               20/Aug/2018 37800
               1/Sep/2018  21500
               30/Aug/2018 42000
John Tam       12/Sep/2018 35000
run;

data temp;
	 set testing;
	 retain holder;
	 if not missing(name) then holder=name;
run;
proc sort data=temp out=temp;
	by holder latest_sales_date;
run;&lt;BR /&gt;&lt;BR /&gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want(drop=holder hdate person_sales_total);
	 retain days person_sales_total 0 hdate ;
	 set temp;
	 by holder latest_sales_date;
	 running_total + person_total_sales;
	 Person_sales_total + person_total_sales;
	 if first.holder then hdate = latest_sales_date;
	 if last.holder then days = (latest_sales_date - hdate);
	 name=holder;
	 person_total_sales = person_sales_total;
	 if last.holder then 
		do;
			output;
			person_total_sales = 0;
		end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 03 Nov 2018 14:56:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-variables-from-existing-variables/m-p/510165#M137276</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-11-03T14:56:37Z</dc:date>
    </item>
    <item>
      <title>Re: Creating variables from existing variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-variables-from-existing-variables/m-p/510166#M137277</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/244119"&gt;@blowsnow__&lt;/a&gt;&amp;nbsp; is your expectation one datastep or one pass of the dataset?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Plz clarify as within&amp;nbsp; a datastep , we can have multiple passes&lt;/P&gt;</description>
      <pubDate>Sat, 03 Nov 2018 14:50:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-variables-from-existing-variables/m-p/510166#M137277</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-03T14:50:30Z</dc:date>
    </item>
    <item>
      <title>Re: Creating variables from existing variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-variables-from-existing-variables/m-p/510170#M137278</link>
      <description>The condition is that I must use only one datastep</description>
      <pubDate>Sat, 03 Nov 2018 14:58:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-variables-from-existing-variables/m-p/510170#M137278</guid>
      <dc:creator>blowsnow__</dc:creator>
      <dc:date>2018-11-03T14:58:19Z</dc:date>
    </item>
    <item>
      <title>Re: Creating variables from existing variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-variables-from-existing-variables/m-p/510173#M137280</link>
      <description>&lt;P&gt;that changes what I have already posted.&amp;nbsp; It doesn't meet the requirements since the requirements were not fully stated.&lt;/P&gt;</description>
      <pubDate>Sat, 03 Nov 2018 15:04:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-variables-from-existing-variables/m-p/510173#M137280</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-11-03T15:04:29Z</dc:date>
    </item>
    <item>
      <title>Re: Creating variables from existing variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-variables-from-existing-variables/m-p/510174#M137281</link>
      <description>&lt;P&gt;You just need to read the name value into a dummy column and then save it into the real Name variable when it is not empty. Use RETAIN the carry the old values of NAME forward.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is sketch of what you need to do.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input dummy $ 1-15 ...... ;
name=coalescec(dummy,name);
retain name;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 03 Nov 2018 15:06:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-variables-from-existing-variables/m-p/510174#M137281</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-03T15:06:19Z</dc:date>
    </item>
    <item>
      <title>Single observation for each variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-variables-from-existing-variables/m-p/510184#M137305</link>
      <description>&lt;P&gt;Greetings all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to read a data set into the&amp;nbsp;following table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Capture.PNG" style="width: 478px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/24629i24A54C05D34A4E0B/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I try to run my program, however, the Name column contains more than one observation for each person. What can I do to make the output contains only one name for each person? And the same goes for the date column, how can I only select the most recent date to show in my output table? Here is what I have so far.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data Sales_Total ;&lt;BR /&gt;infile datalines firstobs=2 ;&lt;BR /&gt;length Dummy Name $15 Latest_Sales_Date Total_Sales 8;&lt;BR /&gt;input dummy $15. Latest_Sales_Date date11. Total_Sales ;&lt;BR /&gt;retain name;&lt;BR /&gt;name=coalescec(dummy,name);&lt;BR /&gt;drop dummy;&lt;BR /&gt;datalines;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;1234567890123456789012345678901234567890&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;David Wong&amp;nbsp; &amp;nbsp; &amp;nbsp;1/Aug/2018&amp;nbsp; 13200 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Brian Leung&amp;nbsp; &amp;nbsp; 15/Sep/2018 23450&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10/Sep/2018 33000&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Mary Chan&amp;nbsp; &amp;nbsp; &amp;nbsp; 3/Jul/2018&amp;nbsp; 45600&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20/Aug/2018 37800&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1/Sep/2018&amp;nbsp; 21500&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;30/Aug/2018 42000&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;John Tam&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12/Sep/2018 35000&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Nov 2018 17:08:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-variables-from-existing-variables/m-p/510184#M137305</guid>
      <dc:creator>blowsnow__</dc:creator>
      <dc:date>2018-11-03T17:08:31Z</dc:date>
    </item>
    <item>
      <title>Re: Creating variables from existing variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-variables-from-existing-variables/m-p/510186#M137286</link>
      <description>&lt;P&gt;But even after running this program, I still have multiple observations for each person. How can my output shows only one name; one&amp;nbsp;Latest_Sales_Date&amp;nbsp;number that is the largest among others; and one Total_Sales sum of all the associated sales amount; for each respective salesperson?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data Sales_Total ;&lt;BR /&gt;infile datalines firstobs=2 ;&lt;BR /&gt;length Dummy Name $15 Latest_Sales_Date Total_Sales 8;&lt;BR /&gt;input dummy $15. Latest_Sales_Date date11. Total_Sales ;&lt;BR /&gt;retain name;&lt;BR /&gt;name=coalescec(dummy,name);&lt;BR /&gt;drop dummy;&lt;BR /&gt;datalines;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;1234567890123456789012345678901234567890&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;David Wong&amp;nbsp; &amp;nbsp; &amp;nbsp;1/Aug/2018&amp;nbsp; 13200 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Brian Leung&amp;nbsp; &amp;nbsp; 15/Sep/2018 23450&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10/Sep/2018 33000&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Mary Chan&amp;nbsp; &amp;nbsp; &amp;nbsp; 3/Jul/2018&amp;nbsp; 45600&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20/Aug/2018 37800&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1/Sep/2018&amp;nbsp; 21500&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;30/Aug/2018 42000&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;John Tam&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12/Sep/2018 35000&lt;/FONT&gt;&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;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Capture2.PNG" style="width: 361px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/24630iE8778922D95CCD1E/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture2.PNG" alt="Capture2.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Nov 2018 17:17:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-variables-from-existing-variables/m-p/510186#M137286</guid>
      <dc:creator>blowsnow__</dc:creator>
      <dc:date>2018-11-03T17:17:37Z</dc:date>
    </item>
    <item>
      <title>Re: Single observation for each variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-variables-from-existing-variables/m-p/510187#M137306</link>
      <description>&lt;P&gt;Why did you start a new post for the same question.&amp;nbsp; refer to your last post and follow through with your issue that is the same topic same question in the same post please.&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/244119"&gt;@blowsnow__&lt;/a&gt; prior post same question&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Creating-variables-from-existing-variables/m-p/510186#M137286" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Creating-variables-from-existing-variables/m-p/510186#M137286&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note you also don't have all of the original requirements listed for the same question listed here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-output-the-last-part-data-programming/m-p/510172" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/How-to-output-the-last-part-data-programming/m-p/510172&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img id="robotmad" class="emoticon emoticon-robotmad" src="https://communities.sas.com/i/smilies/16x16_robot-mad.png" alt="Robot Mad" title="Robot Mad" /&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Nov 2018 17:37:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-variables-from-existing-variables/m-p/510187#M137306</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-11-03T17:37:37Z</dc:date>
    </item>
    <item>
      <title>Re: Single observation for each variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-variables-from-existing-variables/m-p/510213#M137307</link>
      <description>&lt;P&gt;I merged the two threads.&lt;/P&gt;</description>
      <pubDate>Sat, 03 Nov 2018 23:00:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-variables-from-existing-variables/m-p/510213#M137307</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-11-03T23:00:04Z</dc:date>
    </item>
  </channel>
</rss>

