<?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 Sum values over repeated variable values in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Sum-values-over-repeated-variable-values/m-p/990656#M43994</link>
    <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following dataset (a dummy dataset that reflects real data):&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data mytab;
    length 
           Value $15 
           VAR1 $80 
           VAR2 $50 
           VAR3 $50;
    
    infile datalines delimiter='|' missover dsd truncover;
    input  Value $ VAR1 $ VAR2 $ VAR3 $;
datalines;
   8 ( 20.5%)|Overall (*)||
   4 ( 10.3%)|ClassA|All|
   1 (  2.6%)||A1|A1
   1 (  2.6%)||A1|A1
   1 (  2.6%)||A1|A1
   1 (  2.6%)||A1|A1
   1 (  2.6%)||A1|A1
   1 (  2.6%)||A2|A2
   1 (  2.6%)|Class345|All|
   1 (  2.6%)||NF1|NF1
;
run;

proc print data=mytab noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As you can see A1 is repeated. Is there a way to get the following?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mytab1;
    length 
           Value $15 
           VAR1 $80 
           VAR2 $50 
           VAR3 $50;
    
    infile datalines delimiter='|' missover dsd truncover;
    input  Value $ VAR1 $ VAR2 $ VAR3 $;
datalines;
   8 ( 20.5%)|Overall (*)||
   4 ( 10.3%)|ClassA|All|
   5 (  13%)||A1|A1
   1 (  2.6%)||A2|A2
   1 (  2.6%)|Class345|All|
   1 (  2.6%)||NF1|NF1
;
run;


proc print data=mytab1 noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In other words I would like to sum over Value for repeated and identical Var2 and Var3.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I thought to add an Index to map repeated values and to sum over them but my issue is that "value" var is char variable and not numeric.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone help me please?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
    <pubDate>Fri, 10 Jul 2026 16:29:57 GMT</pubDate>
    <dc:creator>NewUsrStat</dc:creator>
    <dc:date>2026-07-10T16:29:57Z</dc:date>
    <item>
      <title>Sum values over repeated variable values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-values-over-repeated-variable-values/m-p/990656#M43994</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following dataset (a dummy dataset that reflects real data):&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data mytab;
    length 
           Value $15 
           VAR1 $80 
           VAR2 $50 
           VAR3 $50;
    
    infile datalines delimiter='|' missover dsd truncover;
    input  Value $ VAR1 $ VAR2 $ VAR3 $;
datalines;
   8 ( 20.5%)|Overall (*)||
   4 ( 10.3%)|ClassA|All|
   1 (  2.6%)||A1|A1
   1 (  2.6%)||A1|A1
   1 (  2.6%)||A1|A1
   1 (  2.6%)||A1|A1
   1 (  2.6%)||A1|A1
   1 (  2.6%)||A2|A2
   1 (  2.6%)|Class345|All|
   1 (  2.6%)||NF1|NF1
;
run;

proc print data=mytab noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As you can see A1 is repeated. Is there a way to get the following?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mytab1;
    length 
           Value $15 
           VAR1 $80 
           VAR2 $50 
           VAR3 $50;
    
    infile datalines delimiter='|' missover dsd truncover;
    input  Value $ VAR1 $ VAR2 $ VAR3 $;
datalines;
   8 ( 20.5%)|Overall (*)||
   4 ( 10.3%)|ClassA|All|
   5 (  13%)||A1|A1
   1 (  2.6%)||A2|A2
   1 (  2.6%)|Class345|All|
   1 (  2.6%)||NF1|NF1
;
run;


proc print data=mytab1 noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In other words I would like to sum over Value for repeated and identical Var2 and Var3.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I thought to add an Index to map repeated values and to sum over them but my issue is that "value" var is char variable and not numeric.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone help me please?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jul 2026 16:29:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-values-over-repeated-variable-values/m-p/990656#M43994</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2026-07-10T16:29:57Z</dc:date>
    </item>
    <item>
      <title>Re: Sum values over repeated variable values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-values-over-repeated-variable-values/m-p/990657#M43995</link>
      <description>&lt;P&gt;You cannot ADD strings.&amp;nbsp; You can concatenate them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But why is the variable character if it is something that you want to do arithmetic on?&amp;nbsp; Did something go wrong with your creation of the original dataset?&amp;nbsp; Your starting point looks like a summary of some other dataset? Can you share the original dataset? Can you share the code that made that summary dataset?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It should be simple to change the those strings into numbers using the INPUT() function.&amp;nbsp; Since you seem to have two different numbers in the strings you can use SCAN() to separate them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  num1 = input(scan(value,1,'()'),32.);
  num2 = input(scan(value,2,'()'),percent32.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jul 2026 16:49:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-values-over-repeated-variable-values/m-p/990657#M43995</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-07-10T16:49:04Z</dc:date>
    </item>
    <item>
      <title>Re: Sum values over repeated variable values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-values-over-repeated-variable-values/m-p/990660#M43996</link>
      <description>&lt;P&gt;Agreeing with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;that numbers should not characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you perform the conversion to have numeric values, PROC SUMMARY or PROC MEANS produces the dataset or output you want.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jul 2026 17:54:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-values-over-repeated-variable-values/m-p/990660#M43996</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2026-07-10T17:54:02Z</dc:date>
    </item>
    <item>
      <title>Re: Sum values over repeated variable values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-values-over-repeated-variable-values/m-p/990689#M43997</link>
      <description>&lt;P&gt;As Tom said, you need to transform these characters into numbers and calculated/sum it again and concatenate them back .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data mytab;
    length 
           Value $15 
           VAR1 $80 
           VAR2 $50 
           VAR3 $50;
    
    infile datalines delimiter='|' missover dsd truncover;
    input  Value $ VAR1 $ VAR2 $ VAR3 $;
datalines;
   8 ( 20.5%)|Overall (*)||
   4 ( 10.3%)|ClassA|All|
   1 (  2.6%)||A1|A1
   1 (  2.6%)||A1|A1
   1 (  2.6%)||A1|A1
   1 (  2.6%)||A1|A1
   1 (  2.6%)||A1|A1
   1 (  2.6%)||A2|A2
   1 (  2.6%)|Class345|All|
   1 (  2.6%)||NF1|NF1
;
run;

data mytab2;
 set mytab;
 part1=input(scan(value,1,'( )'),best.);
 part2=input(scan(value,-1,'( )'),percent.);
run;
proc summary data=mytab2 ;
 by var1-var3 notsorted;
 var part1 part2;
 output out=mytab3(drop=_:) sum=;
run;
data mytab4;
 length value $ 20;
 set mytab3;
 value=catx(' ',part1,'(')||tranwrd(put(part2,percent7.1 -r),'  ',' ')||')';
 drop part1 part2;
run;

proc print data=mytab4 noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1783754834246.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/116329i5912A46FDA448E20/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1783754834246.png" alt="Ksharp_0-1783754834246.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Jul 2026 07:27:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-values-over-repeated-variable-values/m-p/990689#M43997</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2026-07-11T07:27:25Z</dc:date>
    </item>
  </channel>
</rss>

