<?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: Help with arrays in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-with-arrays/m-p/338759#M77210</link>
    <description>&lt;P&gt;I am not sure about your output dataset, this doesn't seem to match what you say in the post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is where I got to, so can be a start for you:&lt;/P&gt;
&lt;PRE&gt;data sample;  
   infile datalines missover;  
   input Date $ Type1 Type2 $ Money  P_10 P_108 P_9 O_100 O_98 O_5 P_50 P_3 O_355;  
   datalines;  
20170101 0 A 100  50 10 . 40
20170101 0 A 110 . . . . 110
20170101 1 B 1200 200 . . . . 500 . . 500
20170101 1 B 202 100 . . . . . 102
20170101 5 C 5 . . . . 5
;                             
run;

proc transpose data=sample out=inter;
  by date type1 type2 money notsorted;
  var p_: o_:;
run;
data inter;
  set inter;
  id=input(scan(_name_,2,"_"),best.);
run;

data reference_id;
   infile datalines missover;  
   input ID Descrip $ Status $ category $; 
   datalines;
10	P	PAID	GOOD
108	P	PAID	GOOD		
9	P	PAID	BAD
100	M	PAID	GOOD
98	M	PAID	BAD
5	M	PAID	GOOD
50	P	PAID	BAD
3	P	PAID	GOOD
355	M	PAID	N/A
;
run;

proc sql;
  create table COMB as
  select  distinct
          A.DATE,
          A.TYPE1,
          A.TYPE2,
          A.MONEY,
          catx("_",B.STATUS,B.CATEGORY) as LAB,
          sum(COL1) as VAL
  from    (select * from INTER where COL1 ne .) A
  left join REFERENCE_ID B
  on      A.ID=B.ID
  group by A.DATE,
           A.TYPE1,
           A.TYPE2,
           A.MONEY,
           catx("_",B.STATUS,B.CATEGORY);
quit;
proc transpose data=comb out=want;
  by date type1 type2 money;
  var val;
  id lab;
run;


&lt;/PRE&gt;</description>
    <pubDate>Tue, 07 Mar 2017 11:22:55 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-03-07T11:22:55Z</dc:date>
    <item>
      <title>Help with arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-arrays/m-p/338748#M77204</link>
      <description>&lt;P&gt;&lt;BR /&gt;Hi Guys&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Need some help with this problem.&lt;/P&gt;
&lt;P&gt;This is the two tables I have:&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 sample;  
   infile datalines missover;  
   input Date $ Type1 Type2 $ Money  P_10 P_108 P_9 O_100 O_98 O_5 P_50 P_3 O_355;  
   datalines;  
20170101 0 A 100  50 10 . 40
20170101 0 A 110 . . . . 110
20170101 1 B 1200 200 . . . . 500 . . 500
20170101 1 B 202 100 . . . . . 102
20170101 5 C 5 . . . . 5
;                             
run;

data reference_id;
   infile datalines missover;  
   input ID Descrip $ Status $ category $; 
   datalines;
10	P	PAID	GOOD
108	P	PAID	GOOD		
9	P	PAID	BAD
100	M	PAID	GOOD
98	M	PAID	BAD
5	M	PAID	GOOD
50	P	PAID	BAD
3	P	PAID	GOOD
355	M	PAID	N/A
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;I need to extract all the ID's from sample into an array (remove the prefix) and join it with the ID properties in the reference_id table.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;The ID should be replaced with its respective properties e.g P_10 in sample table equals ID 10 in reference_id table - the output should read P_PAID_GOOD.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This is the output I desire.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data output;
 infile datalines missover;  
 input Date $ Type1 Type2 $ Money P_PAID_GOOD P_PAID_BAD M_PAID_GOOD M_PAID_BAD M_PAID_N_A ;
 datalines;
20170101 0 A 100 60 . 40 
20170101 0 A 110 . . . 110
20170101 1 B 1200 200 . 500 . 500
20170101 1 B 202 100 . . 102 .
20170101 5 C 5 . . . 5 .
 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Mar 2017 10:48:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-arrays/m-p/338748#M77204</guid>
      <dc:creator>Havi</dc:creator>
      <dc:date>2017-03-07T10:48:53Z</dc:date>
    </item>
    <item>
      <title>Re: Help with arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-arrays/m-p/338759#M77210</link>
      <description>&lt;P&gt;I am not sure about your output dataset, this doesn't seem to match what you say in the post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is where I got to, so can be a start for you:&lt;/P&gt;
&lt;PRE&gt;data sample;  
   infile datalines missover;  
   input Date $ Type1 Type2 $ Money  P_10 P_108 P_9 O_100 O_98 O_5 P_50 P_3 O_355;  
   datalines;  
20170101 0 A 100  50 10 . 40
20170101 0 A 110 . . . . 110
20170101 1 B 1200 200 . . . . 500 . . 500
20170101 1 B 202 100 . . . . . 102
20170101 5 C 5 . . . . 5
;                             
run;

proc transpose data=sample out=inter;
  by date type1 type2 money notsorted;
  var p_: o_:;
run;
data inter;
  set inter;
  id=input(scan(_name_,2,"_"),best.);
run;

data reference_id;
   infile datalines missover;  
   input ID Descrip $ Status $ category $; 
   datalines;
10	P	PAID	GOOD
108	P	PAID	GOOD		
9	P	PAID	BAD
100	M	PAID	GOOD
98	M	PAID	BAD
5	M	PAID	GOOD
50	P	PAID	BAD
3	P	PAID	GOOD
355	M	PAID	N/A
;
run;

proc sql;
  create table COMB as
  select  distinct
          A.DATE,
          A.TYPE1,
          A.TYPE2,
          A.MONEY,
          catx("_",B.STATUS,B.CATEGORY) as LAB,
          sum(COL1) as VAL
  from    (select * from INTER where COL1 ne .) A
  left join REFERENCE_ID B
  on      A.ID=B.ID
  group by A.DATE,
           A.TYPE1,
           A.TYPE2,
           A.MONEY,
           catx("_",B.STATUS,B.CATEGORY);
quit;
proc transpose data=comb out=want;
  by date type1 type2 money;
  var val;
  id lab;
run;


&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Mar 2017 11:22:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-arrays/m-p/338759#M77210</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-03-07T11:22:55Z</dc:date>
    </item>
    <item>
      <title>Re: Help with arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-arrays/m-p/338763#M77212</link>
      <description>&lt;P&gt;Here's a different start. &amp;nbsp;I just don't have time to finish it. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because there are so few entries in the second table, taking on a limited set of numeric ID values, this is a good candidate for a rarely uised technique.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;array st {355} $ 1 _temporary_;&lt;/P&gt;
&lt;P&gt;array cat {355} $ 4 _temporary_;&lt;/P&gt;
&lt;P&gt;if _n_=1 then do until (done);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set reference_id end=done;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;st{id} = status;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;cat{id} = category;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This gives you two temporary arrays meaning their elements are automatically retained, and automatically dropped at the end of the DATA step. &amp;nbsp;Most of the array elements are missing, but that won't harm anything. &amp;nbsp;It doesn't take much memory to hold 355 elements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What's left to do in the same DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;set sample;&lt;/P&gt;
&lt;P&gt;array entries {9} P_10 P_108 P_9 O_100 ... O_355;&lt;/P&gt;
&lt;P&gt;do i=1 to 9;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;length P_vs_O $ 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;P_vs_O = vname(entries{i});&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;ID = input(substr (vname(entries{i}), 3), 3.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;* Put pieces in the right buckets;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;*keep/drop as you see fit;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There's probably a detail or two that I left out, but this approach will be as straightforward as it gets (unfortunately so, perhaps).&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 11:37:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-arrays/m-p/338763#M77212</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-03-07T11:37:53Z</dc:date>
    </item>
    <item>
      <title>Re: Help with arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-arrays/m-p/338764#M77213</link>
      <description>&lt;P&gt;In my experience the long format is more useful.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 11:42:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-arrays/m-p/338764#M77213</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-07T11:42:18Z</dc:date>
    </item>
    <item>
      <title>Re: Help with arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-arrays/m-p/338768#M77214</link>
      <description>Thanks a million RW9. Works exactly the way I wanted it to.</description>
      <pubDate>Tue, 07 Mar 2017 11:47:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-arrays/m-p/338768#M77214</guid>
      <dc:creator>Havi</dc:creator>
      <dc:date>2017-03-07T11:47:43Z</dc:date>
    </item>
  </channel>
</rss>

