<?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: long to wide using seq by ID in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/long-to-wide-using-seq-by-ID/m-p/629749#M186314</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, it will be exactly the same results, as serial numbers are incremental (1, 2, etc.).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 05 Mar 2020 09:37:32 GMT</pubDate>
    <dc:creator>ed_sas_member</dc:creator>
    <dc:date>2020-03-05T09:37:32Z</dc:date>
    <item>
      <title>long to wide using seq by ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/long-to-wide-using-seq-by-ID/m-p/629731#M186301</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have raw data of loans.&lt;/P&gt;
&lt;P&gt;For each loan there are multiple rows that shows information about scores in following up periods .&lt;/P&gt;
&lt;P&gt;I want to change the structure of the table from long to wide.&lt;/P&gt;
&lt;P&gt;For each&amp;nbsp;Loan_ID (Customer_ID,Loan_ID,Loan_date,Loan_Month,Loan_sum,Score_Known_Month)&amp;nbsp; there will be only one row and there will be information of Score1,Score2,sscore3....Score11 (which is from fields :score +Seq)&lt;/P&gt;
&lt;P&gt;What is the way to do it with proc transpose?&lt;/P&gt;
&lt;P&gt;What is the way to do it with array?&lt;/P&gt;
&lt;P&gt;what is better way?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; Data Rawtbl;
format Loan_date date9.;
informat Loan_date date9.;
input Customer_ID  Loan_ID Loan_date Loan_Month Loan_sum  Score_Known_Month score serial_no;
cards;
1 777 '23NOV2019'd 1911 3000 1910 7 1
1 777 '23NOV2019'd 1911 3000 1910 7 2
1 999 '17OCT2019'd 1910 1000 1908 7 1
1 999 '17OCT2019'd 1910 1000 1908 9 2
1 999 '17OCT2019'd 1910 1000 1908 7 3
1 999 '17OCT2019'd 1910 1000 1908 7 4
2 888 '27FEB2019'd 1902 900 1901 5 1
2 888 '27FEB2019'd 1902 900 1901 4 2
2 888 '27FEB2019'd 1902 900 1901 5 3
2 888 '27FEB2019'd 1902 900 1901 5 4
2 888 '27FEB2019'd 1902 900 1901 4 5
2 888 '27FEB2019'd 1902 900 1901 3 6
2 888 '27FEB2019'd 1902 900 1901 5 7
2 888 '27FEB2019'd 1902 900 1901 4 8
2 888 '27FEB2019'd 1902 900 1901 4 9
2 888 '27FEB2019'd 1902 900 1901 4 10
2 888 '27FEB2019'd 1902 900 1901 2 11
;
run;

/*Task:*/
/*For each: Customer_ID,Loan_ID,Loan_date,Loan_Month,Loan_sum,Score_Known_Month*/
/*Will have information of:*/
/*Score1 */
/*Score2*/
/*Score3*/
/*.......*/
/*.......*/
/*Score11*/
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Mar 2020 08:39:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/long-to-wide-using-seq-by-ID/m-p/629731#M186301</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-03-05T08:39:48Z</dc:date>
    </item>
    <item>
      <title>Re: long to wide using seq by ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/long-to-wide-using-seq-by-ID/m-p/629733#M186302</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are 2 methods:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=rawtbl out=rawtbl_tr (drop=_name_) prefix=score_;
	var score;
	by Customer_ID  Loan_ID Loan_date Loan_Month Loan_sum  Score_Known_Month;
run;

/* OR */
proc sql noprint;
	select max(nb_score) into:max_nb from 
	(select count(score) as nb_score from rawtbl
	group by Customer_ID, Loan_ID, Loan_date, Loan_Month, Loan_sum, Score_Known_Month);
quit;

data rawtbl_array;
	set rawtbl;
	array score_(&amp;amp;max_nb.);
 	by Customer_ID  Loan_ID Loan_date Loan_Month Loan_sum  Score_Known_Month;
    retain score;
 	if first.Score_Known_Month then do;
 		i=0;
 		call missing (of score_(*));
 	end;
 	retain score_;
 	i+1;
	score_(i) = score;
	if last.Score_Known_Month then output;
	drop score i serial_no;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Mar 2020 08:52:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/long-to-wide-using-seq-by-ID/m-p/629733#M186302</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-03-05T08:52:40Z</dc:date>
    </item>
    <item>
      <title>Re: long to wide using seq by ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/long-to-wide-using-seq-by-ID/m-p/629746#M186313</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;I want to ask please about proc transpose:&lt;/P&gt;
&lt;P&gt;Why don't we need to use ID statement in this case?&lt;/P&gt;
&lt;P&gt;Is it equivalent way if I add ID statement with&amp;nbsp; serial_no field?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=rawtbl out=rawtbl_tr (drop=_name_) prefix=score_;
var score;
by Customer_ID  Loan_ID Loan_date Loan_Month Loan_sum  Score_Known_Month;
ID serial_no;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Mar 2020 09:32:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/long-to-wide-using-seq-by-ID/m-p/629746#M186313</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-03-05T09:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: long to wide using seq by ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/long-to-wide-using-seq-by-ID/m-p/629749#M186314</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, it will be exactly the same results, as serial numbers are incremental (1, 2, etc.).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Mar 2020 09:37:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/long-to-wide-using-seq-by-ID/m-p/629749#M186314</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-03-05T09:37:32Z</dc:date>
    </item>
  </channel>
</rss>

