<?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: Adding Based on File Name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-Based-on-File-Name/m-p/430681#M281628</link>
    <description>&lt;P&gt;something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
array t(*) CYOW_ARR_NH

CYOW_ARR_H

CYOW_ARR_TOT

CYOW_DEP_NH

CYOW_DEP_H

CYOW_DEP_TOT (6*1)
;
run;

proc transpose data=have out=_have;
run;

proc sql;
create table want as
select _NAME_, sum(col1) as sum
from _have
group by _name_;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 24 Jan 2018 21:20:45 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-01-24T21:20:45Z</dc:date>
    <item>
      <title>Adding Based on File Name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-Based-on-File-Name/m-p/430675#M281627</link>
      <description>&lt;P&gt;suppose I have the following variables that are organized like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CYOW_ARR_NH&lt;/P&gt;&lt;P&gt;CYOW_ARR_H&lt;/P&gt;&lt;P&gt;CYOW_ARR_TOT&lt;/P&gt;&lt;P&gt;CYOW_DEP_NH&lt;/P&gt;&lt;P&gt;CYOW_DEP_H&lt;/P&gt;&lt;P&gt;CYOW_DEP_TOT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to create a sum based on file name. For example, sum up all variables that have _ARR_NH, then maybe _DEP_H. That is, the variable can have anything in the first four letters, but add based on the suffix.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 21:09:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-Based-on-File-Name/m-p/430675#M281627</guid>
      <dc:creator>BCNAV</dc:creator>
      <dc:date>2018-01-24T21:09:18Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Based on File Name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-Based-on-File-Name/m-p/430681#M281628</link>
      <description>&lt;P&gt;something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
array t(*) CYOW_ARR_NH

CYOW_ARR_H

CYOW_ARR_TOT

CYOW_DEP_NH

CYOW_DEP_H

CYOW_DEP_TOT (6*1)
;
run;

proc transpose data=have out=_have;
run;

proc sql;
create table want as
select _NAME_, sum(col1) as sum
from _have
group by _name_;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Jan 2018 21:20:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-Based-on-File-Name/m-p/430681#M281628</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-24T21:20:45Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Based on File Name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-Based-on-File-Name/m-p/430684#M281629</link>
      <description>&lt;P&gt;thanks...suppose there can be any number of variables...is there a way to do this in the general case?&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 21:32:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-Based-on-File-Name/m-p/430684#M281629</guid>
      <dc:creator>BCNAV</dc:creator>
      <dc:date>2018-01-24T21:32:17Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Based on File Name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-Based-on-File-Name/m-p/430687#M281630</link>
      <description>&lt;P&gt;A dynamic approach is to transpose, generate a new variable that allows you to map the variables to the correct group and then summarize. In SQL you can do the last two steps at once.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 21:37:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-Based-on-File-Name/m-p/430687#M281630</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-24T21:37:44Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Based on File Name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-Based-on-File-Name/m-p/430688#M281631</link>
      <description>&lt;P&gt;yes, the data have is just an example i took it from you. But the grouping is achieved by proc transpose regardless. So don't take notice of data have. Just the approach is transpose and group by. simple as that!!!!&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 21:38:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-Based-on-File-Name/m-p/430688#M281631</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-24T21:38:03Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Based on File Name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-Based-on-File-Name/m-p/430692#M281632</link>
      <description>&lt;P&gt;A more generic version ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc transpose data=have out=_have;&lt;/P&gt;
&lt;P&gt;var _numeric_;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set _have;&lt;/P&gt;
&lt;P&gt;prefix = scan(_name_, 1, '_');&lt;/P&gt;
&lt;P&gt;suffix = substr(_name_, 1 + length(prefix));&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now your data set is ready to sum up COL1 ... you can group by SUFFIX or even PREFIX if that makes sense.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 21:50:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-Based-on-File-Name/m-p/430692#M281632</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-24T21:50:45Z</dc:date>
    </item>
  </channel>
</rss>

