<?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: Experienced SAS user needing to know how to turn a dataset around?? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Experienced-SAS-user-needing-to-know-how-to-turn-a-dataset/m-p/14040#M1771</link>
    <description>Message was edited by: polingjw

Message was edited by: polingjw</description>
    <pubDate>Mon, 21 Feb 2011 12:47:13 GMT</pubDate>
    <dc:creator>polingjw</dc:creator>
    <dc:date>2011-02-21T12:47:13Z</dc:date>
    <item>
      <title>Experienced SAS user needing to know how to turn a dataset around??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Experienced-SAS-user-needing-to-know-how-to-turn-a-dataset/m-p/14039#M1770</link>
      <description>Hi I'm an experienced user of SAS but have encountered a problem I've never faced before.&lt;BR /&gt;
&lt;BR /&gt;
Basically I have a dataset that looks something like this:&lt;BR /&gt;
&lt;BR /&gt;
Product    Open_date     Amount_0111      Amount_0211     Amount_0311     Create_0111     Create_0211     Create_0311.&lt;BR /&gt;
&lt;BR /&gt;
Where the balance and limit variables are in the format Balance_mmyy where mmyy is open date&lt;BR /&gt;
&lt;BR /&gt;
However what I want the dataset to look like is this:&lt;BR /&gt;
&lt;BR /&gt;
Product    Open_date     Month      Amount       Create&lt;BR /&gt;
Blah         01/01/2010     1             100              1000&lt;BR /&gt;
Blah         01/01/2010     2             150              1000&lt;BR /&gt;
Blah         01/01/2010     3             180              1000&lt;BR /&gt;
Blah2        01/01/2010     1             100              1000&lt;BR /&gt;
Blah2        01/01/2010     2             150              1000&lt;BR /&gt;
Blah2        01/01/2010     3             180              1000&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
where month is number of months since the product was opened.&lt;BR /&gt;
&lt;BR /&gt;
Can anyone shed any light?&lt;BR /&gt;
&lt;BR /&gt;
Thanks</description>
      <pubDate>Mon, 21 Feb 2011 12:02:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Experienced-SAS-user-needing-to-know-how-to-turn-a-dataset/m-p/14039#M1770</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-02-21T12:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: Experienced SAS user needing to know how to turn a dataset around??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Experienced-SAS-user-needing-to-know-how-to-turn-a-dataset/m-p/14040#M1771</link>
      <description>Message was edited by: polingjw

Message was edited by: polingjw</description>
      <pubDate>Mon, 21 Feb 2011 12:47:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Experienced-SAS-user-needing-to-know-how-to-turn-a-dataset/m-p/14040#M1771</guid>
      <dc:creator>polingjw</dc:creator>
      <dc:date>2011-02-21T12:47:13Z</dc:date>
    </item>
    <item>
      <title>Re: Experienced SAS user needing to know how to turn a dataset around??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Experienced-SAS-user-needing-to-know-how-to-turn-a-dataset/m-p/14041#M1772</link>
      <description>I'm going to try pasting the code again. I think that my original posting was changed because it had an "i" enclosed in brackets.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data old;&lt;BR /&gt;
	input Product $ Open_date:mmddyy10.  Amount_0111 Amount_0211 Amount_0311 Create_0111 Create_0211 Create_0311;&lt;BR /&gt;
	format open_date mmddyy10.;&lt;BR /&gt;
	datalines;&lt;BR /&gt;
	blah 01/01/2010 100 150 180 1000 1000 1000&lt;BR /&gt;
	blah2 02/01/2010 100 150 180 1000 1000 1000&lt;BR /&gt;
	;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data new;&lt;BR /&gt;
	set old;&lt;BR /&gt;
	array amounts{*} amount:;&lt;BR /&gt;
	array creates{*} create:;&lt;BR /&gt;
	do k=1 to dim(amounts);&lt;BR /&gt;
		amount = amounts{k};&lt;BR /&gt;
		month = scan(vname(amounts{k}), 2, '_');&lt;BR /&gt;
		do j=1 to dim(creates);&lt;BR /&gt;
			if month=scan(vname(creates&lt;J&gt;), 2, '_') then do;&lt;BR /&gt;
				create=creates{j};&lt;BR /&gt;
				leave;&lt;BR /&gt;
			end;&lt;BR /&gt;
		end;&lt;BR /&gt;
		output;&lt;BR /&gt;
	end;&lt;BR /&gt;
	keep product open_date month amount create;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc print data=new noobs;&lt;BR /&gt;
	var product open_date month amount create;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;/J&gt;</description>
      <pubDate>Mon, 21 Feb 2011 12:59:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Experienced-SAS-user-needing-to-know-how-to-turn-a-dataset/m-p/14041#M1772</guid>
      <dc:creator>polingjw</dc:creator>
      <dc:date>2011-02-21T12:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: Experienced SAS user needing to know how to turn a dataset around??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Experienced-SAS-user-needing-to-know-how-to-turn-a-dataset/m-p/14042#M1773</link>
      <description>Very well done that man, thats exactly what I needed&lt;BR /&gt;
&lt;BR /&gt;
Thank you so much!&lt;BR /&gt;
Rgds</description>
      <pubDate>Mon, 21 Feb 2011 13:21:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Experienced-SAS-user-needing-to-know-how-to-turn-a-dataset/m-p/14042#M1773</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-02-21T13:21:04Z</dc:date>
    </item>
    <item>
      <title>Re: Experienced SAS user needing to know how to turn a dataset around??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Experienced-SAS-user-needing-to-know-how-to-turn-a-dataset/m-p/14043#M1774</link>
      <description>You might consider a 2 PROC TRANSPOSE solution, aka flip and half flop.  You don't have to fiddle with arrays and the same code works for two variables as you have or any number of variables of the samve type and naming convention.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data test;&lt;BR /&gt;
   input Product:$8. Open_date:mmddyy8. Amount_0111 Amount_0211 Amount_0311 Create_0111 Create_0211 Create_0311;&lt;BR /&gt;
   format o: date.;&lt;BR /&gt;
   cards;&lt;BR /&gt;
Blah    01012011  100         150         180         1000        1000        1000&lt;BR /&gt;
Blah2   01012011  100         150         180         1000        1000        1000&lt;BR /&gt;
;;;;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc transpose data=test out=flip;&lt;BR /&gt;
   by product open_date;&lt;BR /&gt;
   run;&lt;BR /&gt;
data tall;&lt;BR /&gt;
   set tall;&lt;BR /&gt;
   month = intck('month',open_date,input(cats('01',scan(_name_,-1,'_')),ddmmyy.));&lt;BR /&gt;
   _name_ = scan(_name_,1,'_');&lt;BR /&gt;
   run;&lt;BR /&gt;
proc sort data=tall;&lt;BR /&gt;
   by product open_date month _name_;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc transpose data=tall out=halfflop;&lt;BR /&gt;
   by product open_date month;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
                   Open_&lt;BR /&gt;
Obs    Product     date      month    _NAME_    Amount    Create&lt;BR /&gt;
&lt;BR /&gt;
 1      Blah      01JAN11      0       COL1       100      1000&lt;BR /&gt;
 2      Blah      01JAN11      1       COL1       150      1000&lt;BR /&gt;
 3      Blah      01JAN11      2       COL1       180      1000&lt;BR /&gt;
 4      Blah2     01JAN11      0       COL1       100      1000&lt;BR /&gt;
 5      Blah2     01JAN11      1       COL1       150      1000&lt;BR /&gt;
 6      Blah2     01JAN11      2       COL1       180      1000&lt;BR /&gt;
[/pre]</description>
      <pubDate>Mon, 21 Feb 2011 14:47:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Experienced-SAS-user-needing-to-know-how-to-turn-a-dataset/m-p/14043#M1774</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2011-02-21T14:47:42Z</dc:date>
    </item>
  </channel>
</rss>

