<?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: I have a real time scenario in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/I-have-a-real-time-scenario/m-p/80468#M23150</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I tried like this, but&amp;nbsp; i am not getting accurate answer&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The actual data is in dataset&amp;nbsp; smple&lt;/P&gt;&lt;P&gt;DATA SAMPLE1;&lt;/P&gt;&lt;P&gt;LENGTH CURRENCY CURRENCY1 $50;&lt;/P&gt;&lt;P&gt;SET SAMPLE;&lt;/P&gt;&lt;P&gt;BY CUST_ID;&lt;/P&gt;&lt;P&gt;IF FIRST.CUST_ID THEN CURRENCY1='';&lt;/P&gt;&lt;P&gt;PUT _ALL_;&lt;/P&gt;&lt;P&gt;CURRENCY1=CATX(',',trim(CURRENCY1),trim(CURRENCY));&lt;/P&gt;&lt;P&gt;IF LAST.CUST_ID;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 20 May 2013 19:12:10 GMT</pubDate>
    <dc:creator>sahaji</dc:creator>
    <dc:date>2013-05-20T19:12:10Z</dc:date>
    <item>
      <title>I have a real time scenario</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/I-have-a-real-time-scenario/m-p/80463#M23145</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;BR /&gt;I have a dataset with the following info&lt;/P&gt;&lt;P&gt;1234 30004 USD&lt;/P&gt;&lt;P&gt;1234 30012 USD&lt;/P&gt;&lt;P&gt;1289 30056 USD&lt;/P&gt;&lt;P&gt;1389 45009 INR&lt;/P&gt;&lt;P&gt;1456 56789 INR&lt;/P&gt;&lt;P&gt;1456 30067 USD&lt;/P&gt;&lt;P&gt;1567 30099 USD&lt;/P&gt;&lt;P&gt;1567 67890 GBP&lt;/P&gt;&lt;P&gt;1567 30088 INR&lt;/P&gt;&lt;P&gt;1567 30092 INR&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need ouput like this&lt;/P&gt;&lt;P&gt;1234&amp;nbsp;&amp;nbsp; USD&lt;/P&gt;&lt;P&gt;1289&amp;nbsp;&amp;nbsp; USD&lt;/P&gt;&lt;P&gt;1389&amp;nbsp;&amp;nbsp; INR&lt;/P&gt;&lt;P&gt;1456&amp;nbsp;&amp;nbsp; INR,USD&lt;/P&gt;&lt;P&gt;1567&amp;nbsp;&amp;nbsp; USD,GBP,INR&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;how to do it,please help me&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 May 2013 18:05:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/I-have-a-real-time-scenario/m-p/80463#M23145</guid>
      <dc:creator>sahaji</dc:creator>
      <dc:date>2013-05-20T18:05:01Z</dc:date>
    </item>
    <item>
      <title>Re: I have a real time scenario</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/I-have-a-real-time-scenario/m-p/80464#M23146</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt; input id1 $ id2 $ currency $;&lt;/P&gt;&lt;P&gt; cards;&lt;/P&gt;&lt;P&gt;1234 30004 USD&lt;/P&gt;&lt;P&gt;1234 30012 USD&lt;/P&gt;&lt;P&gt;1289 30056 USD&lt;/P&gt;&lt;P&gt;1389 45009 INR&lt;/P&gt;&lt;P&gt;1456 56789 INR&lt;/P&gt;&lt;P&gt;1456 30067 USD&lt;/P&gt;&lt;P&gt;1567 30099 USD&lt;/P&gt;&lt;P&gt;1567 67890 GBP&lt;/P&gt;&lt;P&gt;1567 30088 INR&lt;/P&gt;&lt;P&gt;1567 30092 INR&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; select max (ct) into :ct from (select count(*) as ct from have group by id1) ;quit; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;array t(&amp;amp;ct) $3 _temporary_;&lt;/P&gt;&lt;P&gt;call missing(of t(*));&lt;/P&gt;&lt;P&gt;&amp;nbsp; do _n_=1 by 1 until (last.id1);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;by id1 notsorted;&lt;/P&gt;&lt;P&gt;if currency not in t then&lt;/P&gt;&lt;P&gt;t(_n_)=currency;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cat_currency=catx(',', of t(*));&lt;/P&gt;&lt;P&gt;&amp;nbsp; keep id1 cat_currency;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As you can see, this code is not as efficient as I want it to be, an additional pre-process has to be done to get the range of array().&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 May 2013 18:29:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/I-have-a-real-time-scenario/m-p/80464#M23146</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-05-20T18:29:51Z</dc:date>
    </item>
    <item>
      <title>Re: I have a real time scenario</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/I-have-a-real-time-scenario/m-p/80465#M23147</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Alterrnate solution -&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp; create table want1 as&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select id&lt;BR /&gt;&amp;nbsp;&amp;nbsp; , currency&lt;BR /&gt;&amp;nbsp;&amp;nbsp; from have&lt;BR /&gt; group by 1,2&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; order by 1,2;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;proc transpose data=want1 out=want_wide;&lt;BR /&gt;&amp;nbsp; by id;&lt;BR /&gt;&amp;nbsp; var currency;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data want_final;&lt;BR /&gt;&amp;nbsp; set want_wide;&lt;BR /&gt;&amp;nbsp; currency1=trim(col1)||' '||trim(col2)||' '||trim(col3);&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 May 2013 18:34:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/I-have-a-real-time-scenario/m-p/80465#M23147</guid>
      <dc:creator>sascom10</dc:creator>
      <dc:date>2013-05-20T18:34:07Z</dc:date>
    </item>
    <item>
      <title>Re: I have a real time scenario</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/I-have-a-real-time-scenario/m-p/80466#M23148</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have over-complicated your problem, just simply do:&lt;/P&gt;&lt;P&gt;data want1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do until (last.id1);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;by id1 notsorted;&lt;/P&gt;&lt;P&gt;length cat_currency $50;&lt;/P&gt;&lt;P&gt;if findw(cat_currency,currency)=0 then cat_currency=catx(',',cat_currency,currency);&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; keep id1 cat_currency;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;No array or macro variable is needed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 May 2013 18:39:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/I-have-a-real-time-scenario/m-p/80466#M23148</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-05-20T18:39:20Z</dc:date>
    </item>
    <item>
      <title>Re: I have a real time scenario</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/I-have-a-real-time-scenario/m-p/80467#M23149</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the reply and can you please provide the code using base sas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 May 2013 18:39:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/I-have-a-real-time-scenario/m-p/80467#M23149</guid>
      <dc:creator>sahaji</dc:creator>
      <dc:date>2013-05-20T18:39:44Z</dc:date>
    </item>
    <item>
      <title>Re: I have a real time scenario</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/I-have-a-real-time-scenario/m-p/80468#M23150</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I tried like this, but&amp;nbsp; i am not getting accurate answer&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The actual data is in dataset&amp;nbsp; smple&lt;/P&gt;&lt;P&gt;DATA SAMPLE1;&lt;/P&gt;&lt;P&gt;LENGTH CURRENCY CURRENCY1 $50;&lt;/P&gt;&lt;P&gt;SET SAMPLE;&lt;/P&gt;&lt;P&gt;BY CUST_ID;&lt;/P&gt;&lt;P&gt;IF FIRST.CUST_ID THEN CURRENCY1='';&lt;/P&gt;&lt;P&gt;PUT _ALL_;&lt;/P&gt;&lt;P&gt;CURRENCY1=CATX(',',trim(CURRENCY1),trim(CURRENCY));&lt;/P&gt;&lt;P&gt;IF LAST.CUST_ID;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 May 2013 19:12:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/I-have-a-real-time-scenario/m-p/80468#M23150</guid>
      <dc:creator>sahaji</dc:creator>
      <dc:date>2013-05-20T19:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: I have a real time scenario</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/I-have-a-real-time-scenario/m-p/80469#M23151</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You need to check for currency to already be in currency1. Also, trim is not necessary in in catx arguments, but it is in findw word argument. Most importantly, you must use a retain statement on currency1 because otherwise it is reset to missing at every iteration. Try it this way :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;DATA SAMPLE1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;LENGTH CURRENCY CURRENCY1 $50;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;retain currency1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;SET SAMPLE;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;BY CUST_ID;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;IF FIRST.CUST_ID THEN call missing(CURRENCY1);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if findw(currency1,trim(currency))=0 then CURRENCY1=CATX(',', CURRENCY1, CURRENCY);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;IF LAST.CUST_ID;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RUN;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 May 2013 20:02:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/I-have-a-real-time-scenario/m-p/80469#M23151</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2013-05-20T20:02:57Z</dc:date>
    </item>
    <item>
      <title>Re: I have a real time scenario</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/I-have-a-real-time-scenario/m-p/362232#M64546</link>
      <description>&lt;P&gt;data temp;&lt;BR /&gt;input id zip cntr $;&lt;BR /&gt;cards;&lt;BR /&gt;1234 30004 USD&lt;BR /&gt;1234 30012 USD&lt;BR /&gt;1289 30056 USD&lt;BR /&gt;1389 45009 INR&lt;BR /&gt;1456 56789 INR&lt;BR /&gt;1456 30067 USD&lt;BR /&gt;1567 30099 USD&lt;BR /&gt;1567 67890 GBP&lt;BR /&gt;1567 30088 INR&lt;BR /&gt;1567 30092 INR&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;proc sort data=temp(drop=zip) out=temp1 nodupkey;&lt;BR /&gt;by id cntr;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data temp2(drop=cntr);&lt;BR /&gt;set temp1;&lt;BR /&gt;retain cntry;&lt;BR /&gt;length cntry $20.;&lt;BR /&gt;by id cntr;&lt;BR /&gt;if first.id and last.id then do;&lt;BR /&gt;cntry=cntr;&lt;BR /&gt;output temp2;&lt;BR /&gt;end;&lt;BR /&gt;else if first.id and last.id = 0 then do;&lt;BR /&gt;cntry=cntr;&lt;BR /&gt;end;&lt;BR /&gt;else if first.id = 0 and last.id = 0 then do;&lt;BR /&gt;cntry = catx(',',cntry,cntr);&lt;BR /&gt;end;&lt;BR /&gt;else if first.id = 0 and last.id = 1 then do;&lt;BR /&gt;cntry = catx(',',cntry,cntr);&lt;BR /&gt;output temp2;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sat, 27 May 2017 20:37:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/I-have-a-real-time-scenario/m-p/362232#M64546</guid>
      <dc:creator>avishek2411</dc:creator>
      <dc:date>2017-05-27T20:37:17Z</dc:date>
    </item>
    <item>
      <title>Re: I have a real time scenario</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/I-have-a-real-time-scenario/m-p/503544#M72748</link>
      <description>&lt;BR /&gt;data d;&lt;BR /&gt;input ID SAL CU$;&lt;BR /&gt;datalines;&lt;BR /&gt;1234 30004 USD&lt;BR /&gt;&lt;BR /&gt;1234 30012 USD&lt;BR /&gt;&lt;BR /&gt;1289 30056 USD&lt;BR /&gt;&lt;BR /&gt;1389 45009 INR&lt;BR /&gt;&lt;BR /&gt;1456 56789 INR&lt;BR /&gt;&lt;BR /&gt;1456 30067 USD&lt;BR /&gt;&lt;BR /&gt;1567 30099 USD&lt;BR /&gt;&lt;BR /&gt;1567 67890 GBP&lt;BR /&gt;&lt;BR /&gt;1567 30088 INR&lt;BR /&gt;&lt;BR /&gt;1567 30092 INR&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data s;&lt;BR /&gt;length curr_joined $ 50;&lt;BR /&gt;retain curr_joined ;&lt;BR /&gt;set d;&lt;BR /&gt;&lt;BR /&gt;by id;&lt;BR /&gt;if first.ID then curr_joined=CU;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;else if not exist(curr_joined) &amp;amp;&amp;amp; findw(curr_joined,CU) =0&lt;BR /&gt;THEN curr_joined = catx(', ', curr_joined, CU);&lt;BR /&gt;&lt;BR /&gt;if last.ID;&lt;BR /&gt;&lt;BR /&gt;run;</description>
      <pubDate>Thu, 11 Oct 2018 20:02:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/I-have-a-real-time-scenario/m-p/503544#M72748</guid>
      <dc:creator>mk0459</dc:creator>
      <dc:date>2018-10-11T20:02:03Z</dc:date>
    </item>
    <item>
      <title>Re: I have a real time scenario</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/I-have-a-real-time-scenario/m-p/504135#M72759</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/118825"&gt;@avishek2411&lt;/a&gt;: I think you have the right idea.&amp;nbsp; But the data step after proc sort can be simplified greatly by have a SET and BY statement inside a DO UNTIL (LAST.ID) loop:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
input id zip cntr $;
cards;
1234 30004 USD
1234 30012 USD
1289 30056 USD
1389 45009 INR
1456 56789 INR
1456 30067 USD
1567 30099 USD
1567 67890 GBP
1567 30088 INR
1567 30092 INR
;

proc sort data=temp(drop=zip) out=temp1 nodupkey;
by id cntr;
run;
data want;
  do until (last.id);
	set temp1;
	by id;
    length cntr_list $20;
	cntr_list=catx(',',cntr_list,cntr);
  end;
  drop cntr;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;The only downside is that the currency list for each id&amp;nbsp;is alphabetic.&amp;nbsp; It is no longer in the order of appearance.&amp;nbsp; Have to ask &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/49413"&gt;@sahaji&lt;/a&gt;&amp;nbsp;whether that is meaningful deficiency.&lt;/P&gt;</description>
      <pubDate>Sun, 14 Oct 2018 21:47:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/I-have-a-real-time-scenario/m-p/504135#M72759</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-10-14T21:47:08Z</dc:date>
    </item>
  </channel>
</rss>

