<?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: Array statement help in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Array-statement-help/m-p/314129#M68366</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That doesn't work for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just get blanks when I run your code - also, I want it to output a data set and not a table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Thu, 24 Nov 2016 16:34:02 GMT</pubDate>
    <dc:creator>CamRutherford</dc:creator>
    <dc:date>2016-11-24T16:34:02Z</dc:date>
    <item>
      <title>Array statement help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-statement-help/m-p/314120#M68361</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset in SAS that looks like the below but I'm looking to do the following and think an Array statement is the best way to do so...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My current data&lt;/P&gt;&lt;PRE&gt;SBR_ID	Value
1234	A
1234	B
5432	A
6789	A
5432	C
1234	B
5432	B
6789	A
6789	C&lt;/PRE&gt;&lt;P&gt;I want my data set to end up like this whereby for each SBR_ID it will sum the amount of times that value appears.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;SBR_ID	A	B	C
1234	1	2	
5432	1	1	1
6789	2	0	1&lt;/PRE&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2016 15:39:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-statement-help/m-p/314120#M68361</guid>
      <dc:creator>CamRutherford</dc:creator>
      <dc:date>2016-11-24T15:39:52Z</dc:date>
    </item>
    <item>
      <title>Re: Array statement help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-statement-help/m-p/314128#M68365</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Although you could use a DATA step and may or may not need an ARRAY statement,&amp;nbsp; if you want just a report, you could use PROC REPORT or PROC TABULATE. If you want a summary report AND a dataset, then PROC REPORT can do both for you with one pass through the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Here's the program:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fakedata;
  infile datalines;
  input SBR_ID	Value $;
return;
datalines;
1234	A
1234	B
5432	A
6789	A
5432	C
1234	B
5432	B
6789	A
6789	C
;
run;
  
title 'Report Showing Summary';
proc report data=fakedata 
            out=work.trans_sum(rename=(_c2_=A _c3_=B _c4_=C)drop=_break_);
  column sbr_id n,value;
  define sbr_id / group;
  define value / across;
  define n / ' ';
run;
  
proc print data=work.trans_sum;
  title 'Data set created with PROC REPORT';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; And here's the report and a PROC PRINT of the dataset:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/5999iEB881E0B2C847C18/image-size/original?v=v2&amp;amp;px=-1" alt="use_proc_report.png" title="use_proc_report.png" border="0" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The key to understanding how PROC REPORT can do this means that you have to understand that, by default, the ACROSS items get absolute column numbers assigned to them when PROC REPORT designs the report in a pre-processing phase. So, conceptually, SBR_ID is column 1 and then the column for A is _c2_; the column for B is _C3_ and the column for C is _C4_. Usually, in your output dataset, you do NOT want the absolute column names, so the RENAME statement takes care of renaming the variables in work.trans_sum. And, then, PROC REPORT also makes a "helper" variable called _BREAK_ which isn't necessary, so it is dropped.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; PROC TABULATE would do a report for you, but not an output dataset in transposed structure. Here's the sample TABULATE code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
title 'PROC TABULATE report';
proc tabulate data=fakedata out=work.tabout;
  class sbr_id value;
  table sbr_id,
        n*value;
  keylabel n=' ';
run;

proc print data=work.tabout;
title 'Dataset created by TABULATE';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can test it out for yourself -- if all you need is a report, then either TABULATE or REPORT would do. If you need a DATASET, then DATA step, or REPORT would do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cynthia&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2016 16:23:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-statement-help/m-p/314128#M68365</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2016-11-24T16:23:56Z</dc:date>
    </item>
    <item>
      <title>Re: Array statement help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-statement-help/m-p/314129#M68366</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That doesn't work for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just get blanks when I run your code - also, I want it to output a data set and not a table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2016 16:34:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-statement-help/m-p/314129#M68366</guid>
      <dc:creator>CamRutherford</dc:creator>
      <dc:date>2016-11-24T16:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: Array statement help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-statement-help/m-p/314141#M68372</link>
      <description>&lt;P&gt;Given that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13549"&gt;@Cynthia_sas﻿&lt;/a&gt;&amp;nbsp;generated sample data and the code runs on the sample data, your data either differs or you ran the code incorrectly.&lt;/P&gt;
&lt;P&gt;WIthout seeing what you did, it's a toss up.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use proc freq to get the summaries by ID &amp;nbsp;and then proc transpose to get the dataset desired.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2016 20:27:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-statement-help/m-p/314141#M68372</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-24T20:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: Array statement help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-statement-help/m-p/314194#M68395</link>
      <description>&lt;P&gt;Your want REPORT or want TABLE ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fakedata;
  infile datalines;
  input SBR_ID	Value $;
return;
datalines;
1234	A
1234	B
5432	A
6789	A
5432	C
1234	B
5432	B
6789	A
6789	C
;
run;
proc freq data=fakedata noprint;
 table sbr_id*value/out=freq list nopercent;
run;
proc transpose data=freq out=want;
by sbr_id;
var count;
id value;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Nov 2016 03:06:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-statement-help/m-p/314194#M68395</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-25T03:06:01Z</dc:date>
    </item>
  </channel>
</rss>

