<?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: Consolidate the contents of three variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Consolidate-the-contents-of-three-variables/m-p/684289#M207345</link>
    <description>&lt;P&gt;You would need to store them in arrays.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;, do you have any suggestions?&lt;/P&gt;</description>
    <pubDate>Wed, 16 Sep 2020 15:38:50 GMT</pubDate>
    <dc:creator>pink_poodle</dc:creator>
    <dc:date>2020-09-16T15:38:50Z</dc:date>
    <item>
      <title>Consolidate the contents of three variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Consolidate-the-contents-of-three-variables/m-p/684067#M207260</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to transfer table 1 to table 2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table 1 (see attachment)&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;ID&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Rating&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Watch&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Outlook&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Rating: CCC+&lt;BR /&gt;Rating Range: Mar-20-2020 to Present&lt;BR /&gt;&lt;BR /&gt;Rating: B&lt;BR /&gt;Rating Range: Jan-09-2019 to Mar-20-2020&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;CreditWatch: Watch Neg&lt;BR /&gt;CreditWatch Range: Mar-10-2020 to Mar-20-2020&lt;BR /&gt;&lt;BR /&gt;CreditWatch: Watch Neg&lt;BR /&gt;CreditWatch Range: Aug-29-2019 to Oct-08-2019&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Outlook: Negative&lt;BR /&gt;Outlook Range: Mar-20-2020 to Present&lt;BR /&gt;&lt;BR /&gt;Outlook: Negative&lt;BR /&gt;Outlook Range: Oct-08-2019 to Mar-10-2020&lt;BR /&gt;&lt;BR /&gt;Outlook: Negative&lt;BR /&gt;Outlook Range: Jan-10-2019 to Aug-29-2019&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Rating: BBB+&lt;/P&gt;&lt;P&gt;Rating Range: Jan-07-2019 to Present&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;CreditWatch: Watch Neg&lt;/P&gt;&lt;P&gt;CreditWatch Range: Apr-03-2020 to Present&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Outlook: Stable&lt;/P&gt;&lt;P&gt;Outlook Range: Apr-03-2020 to Present&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table 2&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Obs&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;ID&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;date&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;rating&lt;/P&gt;&lt;/TD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t;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;8&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;4/3/2020&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;BBB+&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are three variables, each of them contains at least one recode.&lt;/P&gt;&lt;P&gt;For each record, it contains a level name (i.e., Rating, CreditWatch or Outlook) and a time range (i.e., Rating range, CreditWatch Range or Outlook range).&lt;/P&gt;&lt;P&gt;Step1, 1) Find the earliest date of these record. In this sample, the earliest record is stored in the ‘Rating’ variable,&lt;/P&gt;&lt;P&gt;‘Rating: B&lt;BR /&gt;Rating Range: Jan-09-2019 to Mar-20-2020’&lt;/P&gt;&lt;P&gt;So, the value in ‘Rating’ converts to ‘rating’ variable in Table 2 as B.&lt;/P&gt;&lt;P&gt;The value in ‘Rating Range’ converts to ‘Date’ variable in Table 2 as 1/09/2019.&lt;/P&gt;&lt;P&gt;2) At the date Jan-09-2019, there is no record of ‘CreditWatch’ or ‘Outlook’.&lt;/P&gt;&lt;P&gt;So, the value in ‘outlookorwatch’ is ‘stable outlook’.&lt;/P&gt;&lt;P&gt;3)The value in ‘Rating’ variable does not change until the next record in ‘rating’ variable happens.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Step2, 1) Find the second earliest date of these record. It is the last record in ‘Outlook’ variable&lt;/P&gt;&lt;P&gt;‘Outlook: Negative&lt;BR /&gt;Outlook Range: Jan-10-2019 to Aug-29-2019’&lt;/P&gt;&lt;P&gt;So, the value in ‘Outlook’ converts to ‘outlookorwatch’ variable in Table 2 as ‘negative outlook’.&lt;/P&gt;&lt;P&gt;the value in ‘Outlook Range’ converts to ‘Date’ variable in Table 2 as 1/10/2019.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Step3, 1) find the third earliest date of these record. It is stored in the ‘Watch’ variable as&lt;/P&gt;&lt;P&gt;‘CreditWatch: Watch Neg&lt;BR /&gt;CreditWatch Range: Aug-29-2019 to Oct-08-2019’&lt;/P&gt;&lt;P&gt;So, the value in ‘Watch’ converts to ‘outlookorwatch’ variable in Table 2 as ‘negative watch’.&lt;/P&gt;&lt;P&gt;the value in ‘Outlook Range’ converts to ‘Date’ variable in Table 2 as 8/29/2019.&lt;/P&gt;&lt;P&gt;Step4, if ‘CreditWatch’ record and ‘Outlook’ happen at same time, I would like to set Note as 1 and does not file any value in ‘outlookorwatch’ variable.&lt;/P&gt;&lt;P&gt;By using ID 2 in table 1 as a sample,&lt;/P&gt;&lt;P&gt;Record in variable ‘Watch’ and ‘Outlook’ happens at the same date (i.e., Apr-03-2020) then the value in ‘outlookorwatch’ variable is empty and Note is 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the code to separate the record in each cell, but I have no idea to put them together (i.e., step1-step4).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;/*matching datastream_ID with WRDS and S&amp;amp;P20200903*/
/*DS_SP_Step2 create S&amp;amp;P_ID,CUSIP,ISIN,CIK,Ticker and name standardization*/
proc import datafile = "C:\Users\70660\Desktop\question20200915.xlsx"
	OUT=sheet1 DBMS=XLSX replace;
	Sheet="sheet1";
	RANGE="A1:D3";
	GETNAMES=YES;
RUN;

data sheet2;
length
rating1 $50.
	rating_range1 $200.
	;
set sheet1;

	rating=tranwrd(rating,'0D0A'x, ','); 
	rating=tranwrd(rating,',,', ','); 
	count=countc(rating,",")+1;
  do i=1 to count by 2;
  rating1=strip(tranwrd(scan(rating,i,','),'Rating:',''));
  rating_range1=strip(tranwrd(scan(rating,i+1,','),'Rating Range:',''));
  output;
 end; 
run;

data sheet3(drop=i count);
	Length
	Credit1 $50.
	Credit_Range1 $200.
	;
	set sheet2;
	Credit=tranwrd(Credit,'0D0A'x, ','); 
	Credit=tranwrd(Credit,',,', ','); 
	count=countc(Credit,",")+1;
  do i=1 to count by 2;
  Credit1=strip(tranwrd(scan(Credit,i,','),'CreditWatch: Watch',''));
  Credit_Range1=strip(tranwrd(scan(Credit,i+1,','),'CreditWatch Range:',''));
  output;
 end;
run;

data SP_table4(drop=i count);
	Length
	Outlook1 $50.
	Outlook_Range1 $200.
	;
	set sheet3;
	Outlook=tranwrd(Outlook,'0D0A'x, ','); 
	Outlook=tranwrd(Outlook,',,', ','); 
	count=countc(Outlook,",")+1;
  do i=1 to count by 2;
  Outlook1=strip(tranwrd(scan(Outlook,i,','),'Outlook:',''));
  Outlook_Range1=strip(tranwrd(scan(Outlook,i+1,','),'Outlook Range:',''));
  output;
 end;
run;&lt;/PRE&gt;&lt;P&gt;Could you please give me some suggestions about this?&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2020 22:27:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Consolidate-the-contents-of-three-variables/m-p/684067#M207260</guid>
      <dc:creator>Alexxxxxxx</dc:creator>
      <dc:date>2020-09-15T22:27:05Z</dc:date>
    </item>
    <item>
      <title>Re: Consolidate the contents of three variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Consolidate-the-contents-of-three-variables/m-p/684289#M207345</link>
      <description>&lt;P&gt;You would need to store them in arrays.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;, do you have any suggestions?&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2020 15:38:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Consolidate-the-contents-of-three-variables/m-p/684289#M207345</guid>
      <dc:creator>pink_poodle</dc:creator>
      <dc:date>2020-09-16T15:38:50Z</dc:date>
    </item>
  </channel>
</rss>

