<?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: Add two rows of data based on if condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Add-two-rows-of-data-based-on-if-condition/m-p/913875#M360147</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/160710"&gt;@anandas&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to add two rows of data and merge into one row. This is a big dataset and I just want to add two specific rows based on an 'If' condition. Something like this;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Have&lt;/STRONG&gt;&lt;/P&gt;
&lt;TABLE width="348"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;Course&lt;/TD&gt;
&lt;TD width="79"&gt;Spring 2022&lt;/TD&gt;
&lt;TD width="64"&gt;Fall 2022&lt;/TD&gt;
&lt;TD width="77"&gt;Spring 2023&lt;/TD&gt;
&lt;TD width="64"&gt;Fall 2023&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;MAT156&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;7&lt;/TD&gt;
&lt;TD&gt;559&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;MAT157&lt;/TD&gt;
&lt;TD&gt;439&lt;/TD&gt;
&lt;TD&gt;529&lt;/TD&gt;
&lt;TD&gt;433&lt;/TD&gt;
&lt;TD&gt;8&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Want&lt;/STRONG&gt;&lt;/P&gt;
&lt;TABLE width="348"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;Course&lt;/TD&gt;
&lt;TD width="79"&gt;Spring 2022&lt;/TD&gt;
&lt;TD width="64"&gt;Fall 2022&lt;/TD&gt;
&lt;TD width="77"&gt;Spring 2023&lt;/TD&gt;
&lt;TD width="64"&gt;Fall 2023&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;MAT158&lt;/TD&gt;
&lt;TD&gt;440&lt;/TD&gt;
&lt;TD&gt;530&lt;/TD&gt;
&lt;TD&gt;440&lt;/TD&gt;
&lt;TD&gt;567&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am adding MAT156 and MAT157 values for each field and creating a new row and calling it MAT158. I searched the library but couldn't find anything of this sort. Any help is appreciated. Thanks.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You haven't stated what IF condition you want to use.&lt;/P&gt;</description>
    <pubDate>Wed, 31 Jan 2024 19:11:05 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2024-01-31T19:11:05Z</dc:date>
    <item>
      <title>Add two rows of data based on if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-two-rows-of-data-based-on-if-condition/m-p/913854#M360141</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to add two rows of data and merge into one row. This is a big dataset and I just want to add two specific rows based on an 'If' condition. Something like this;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Have&lt;/STRONG&gt;&lt;/P&gt;
&lt;TABLE width="348"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;Course&lt;/TD&gt;
&lt;TD width="79"&gt;Spring 2022&lt;/TD&gt;
&lt;TD width="64"&gt;Fall 2022&lt;/TD&gt;
&lt;TD width="77"&gt;Spring 2023&lt;/TD&gt;
&lt;TD width="64"&gt;Fall 2023&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;MAT156&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;7&lt;/TD&gt;
&lt;TD&gt;559&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;MAT157&lt;/TD&gt;
&lt;TD&gt;439&lt;/TD&gt;
&lt;TD&gt;529&lt;/TD&gt;
&lt;TD&gt;433&lt;/TD&gt;
&lt;TD&gt;8&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Want&lt;/STRONG&gt;&lt;/P&gt;
&lt;TABLE width="348"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;Course&lt;/TD&gt;
&lt;TD width="79"&gt;Spring 2022&lt;/TD&gt;
&lt;TD width="64"&gt;Fall 2022&lt;/TD&gt;
&lt;TD width="77"&gt;Spring 2023&lt;/TD&gt;
&lt;TD width="64"&gt;Fall 2023&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;MAT158&lt;/TD&gt;
&lt;TD&gt;440&lt;/TD&gt;
&lt;TD&gt;530&lt;/TD&gt;
&lt;TD&gt;440&lt;/TD&gt;
&lt;TD&gt;567&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am adding MAT156 and MAT157 values for each field and creating a new row and calling it MAT158. I searched the library but couldn't find anything of this sort. Any help is appreciated. Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2024 17:45:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-two-rows-of-data-based-on-if-condition/m-p/913854#M360141</guid>
      <dc:creator>anandas</dc:creator>
      <dc:date>2024-01-31T17:45:36Z</dc:date>
    </item>
    <item>
      <title>Re: Add two rows of data based on if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-two-rows-of-data-based-on-if-condition/m-p/913867#M360144</link>
      <description>&lt;P&gt;Data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
input  Course $	Spring2022 Fall2022 Spring2023	Fall2023; 
cards; 
MAT156	1	1	7	559
MAT157	439	529	433	8
; 
run; 

data temp1(keep= course spring: fall:) temp2(keep= course spring: fall:) temp3(keep= _: rename=(_course=course _Spring2022=Spring2022 _Fall2022=Fall2022 _Spring2023=Spring2023 _Fall2023=Fall2023));
	set have; 
	retain temp1-temp4;
	if course='MAT156' then do;
		temp1=Spring2022;
		temp2=Fall2022; 
		temp3=Spring2023; 
		temp4=Fall2023; 
	end; 
	if course='MAT157' then do; 
		_Course='MAT158'; 
		_Spring2022= sum(temp1,Spring2022);
		_Fall2022= sum(temp2, Fall2022);
		_Spring2023= sum(temp3, Spring2023);
		_Fall2023= sum(temp4,Fall2023);
	end; 
	drop temp:; 
	if course='MAT156' then output temp1; 
	if course='MAT157' then output temp2 temp3;
run;  

data want;
	set temp1-temp3; 
proc print; run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2024 18:30:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-two-rows-of-data-based-on-if-condition/m-p/913867#M360144</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2024-01-31T18:30:24Z</dc:date>
    </item>
    <item>
      <title>Re: Add two rows of data based on if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-two-rows-of-data-based-on-if-condition/m-p/913874#M360146</link>
      <description>&lt;P&gt;IF the numbers for the seasons are to be summed and if you are likely to have many of these sorts of combinations then you may want to learn about custom formats. You can create all sorts of groups using the existing values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have; 
input  Course $	Spring2022 Fall2022 Spring2023	Fall2023; 
cards; 
MAT156	1	1	7	559
MAT157	439	529	433	8
; 
run; 

proc format;
value $coursegrp
'MAT156', 'MAT157' = 'MAT158'
;
run;

proc summary data=have nway;
   class course;
   format course $coursegrp.;
   var Spring2022 Fall2022 Spring2023	Fall2023;
   output out=want (drop=_type_ _freq_) sum=;
run;&lt;BR /&gt;/* or a report*/&lt;BR /&gt;Proc report data=have;&lt;BR /&gt;   columns course Spring2022 Fall2022 Spring2023 Fall2023;&lt;BR /&gt;   define course/group format=$coursegrp.;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;One advantage to a format is that it does not actually change values of the variable(s). So if you make a mistake you don't have to undo anything (which this sort of example would be pretty hard to separate). You can also assign MANY different values to different new displayed values. So one format could address changes in ENG and SCI (or what have you).&lt;/P&gt;
&lt;P&gt;A third less obvious advantage to a format is that you can use different different formats at use time. I have about a dozen formats for different age groups such as pre-teen/teen/adult, or 5-year and 10-year age bands or the ages that a program uses for decision points such as a recommended medical procedure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2024 18:44:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-two-rows-of-data-based-on-if-condition/m-p/913874#M360146</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-01-31T18:44:53Z</dc:date>
    </item>
    <item>
      <title>Re: Add two rows of data based on if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-two-rows-of-data-based-on-if-condition/m-p/913875#M360147</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/160710"&gt;@anandas&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to add two rows of data and merge into one row. This is a big dataset and I just want to add two specific rows based on an 'If' condition. Something like this;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Have&lt;/STRONG&gt;&lt;/P&gt;
&lt;TABLE width="348"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;Course&lt;/TD&gt;
&lt;TD width="79"&gt;Spring 2022&lt;/TD&gt;
&lt;TD width="64"&gt;Fall 2022&lt;/TD&gt;
&lt;TD width="77"&gt;Spring 2023&lt;/TD&gt;
&lt;TD width="64"&gt;Fall 2023&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;MAT156&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;7&lt;/TD&gt;
&lt;TD&gt;559&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;MAT157&lt;/TD&gt;
&lt;TD&gt;439&lt;/TD&gt;
&lt;TD&gt;529&lt;/TD&gt;
&lt;TD&gt;433&lt;/TD&gt;
&lt;TD&gt;8&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Want&lt;/STRONG&gt;&lt;/P&gt;
&lt;TABLE width="348"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;Course&lt;/TD&gt;
&lt;TD width="79"&gt;Spring 2022&lt;/TD&gt;
&lt;TD width="64"&gt;Fall 2022&lt;/TD&gt;
&lt;TD width="77"&gt;Spring 2023&lt;/TD&gt;
&lt;TD width="64"&gt;Fall 2023&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;MAT158&lt;/TD&gt;
&lt;TD&gt;440&lt;/TD&gt;
&lt;TD&gt;530&lt;/TD&gt;
&lt;TD&gt;440&lt;/TD&gt;
&lt;TD&gt;567&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am adding MAT156 and MAT157 values for each field and creating a new row and calling it MAT158. I searched the library but couldn't find anything of this sort. Any help is appreciated. Thanks.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You haven't stated what IF condition you want to use.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2024 19:11:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-two-rows-of-data-based-on-if-condition/m-p/913875#M360147</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-01-31T19:11:05Z</dc:date>
    </item>
    <item>
      <title>Re: Add two rows of data based on if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-two-rows-of-data-based-on-if-condition/m-p/913881#M360150</link>
      <description>&lt;P&gt;The if condition would be to select MAT156 and MAT157 from a series of other courses. The course column has many more course acronyms and I would nee to change only certain courses and MAT156 and MAT157 is one example of the many where I need an if statement specifying the courses that I want changed.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2024 20:54:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-two-rows-of-data-based-on-if-condition/m-p/913881#M360150</guid>
      <dc:creator>anandas</dc:creator>
      <dc:date>2024-01-31T20:54:07Z</dc:date>
    </item>
    <item>
      <title>Re: Add two rows of data based on if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-two-rows-of-data-based-on-if-condition/m-p/913882#M360151</link>
      <description>&lt;P&gt;Thank you for your response.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2024 20:54:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-two-rows-of-data-based-on-if-condition/m-p/913882#M360151</guid>
      <dc:creator>anandas</dc:creator>
      <dc:date>2024-01-31T20:54:52Z</dc:date>
    </item>
    <item>
      <title>Re: Add two rows of data based on if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-two-rows-of-data-based-on-if-condition/m-p/913883#M360152</link>
      <description>Thank you for your response</description>
      <pubDate>Wed, 31 Jan 2024 20:55:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-two-rows-of-data-based-on-if-condition/m-p/913883#M360152</guid>
      <dc:creator>anandas</dc:creator>
      <dc:date>2024-01-31T20:55:12Z</dc:date>
    </item>
    <item>
      <title>Re: Add two rows of data based on if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-two-rows-of-data-based-on-if-condition/m-p/913886#M360154</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/160710"&gt;@anandas&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The if condition would be to select MAT156 and MAT157 from a series of other courses. The course column has many more course acronyms and I would nee to change only certain courses and MAT156 and MAT157 is one example of the many where I need an if statement specifying the courses that I want changed.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have2;
     set have;
     weight=0;
     if course in ('MAT156','MAT157') then weight=1;
run;
proc summary data=have2;
    var spring2022--fall2023;
    weight weight;
    output out=want sum=;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Jan 2024 21:42:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-two-rows-of-data-based-on-if-condition/m-p/913886#M360154</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-01-31T21:42:53Z</dc:date>
    </item>
    <item>
      <title>Re: Add two rows of data based on if condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-two-rows-of-data-based-on-if-condition/m-p/913887#M360155</link>
      <description>Thank you</description>
      <pubDate>Wed, 31 Jan 2024 21:45:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-two-rows-of-data-based-on-if-condition/m-p/913887#M360155</guid>
      <dc:creator>anandas</dc:creator>
      <dc:date>2024-01-31T21:45:27Z</dc:date>
    </item>
  </channel>
</rss>

