<?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: How to manipulate data with the same variable values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-manipulate-data-with-the-same-variable-values/m-p/400672#M97145</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/154111"&gt;@bemariec&lt;/a&gt;&amp;nbsp;your sample data is bad. If you have multiple REF and that's important you should include sample data with multiple REFs so we can replicate your situation. I've made some assumptions and replicated your REF to create at least two in my data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*sample data;
data TEST;
input Ref    Date$    Cycle    side$    value;
datalines;
024301 2017-04-03 1 A 39.969
024301 2017-04-03 1 B 40.645
024301 2017-04-03 1000 A 44.353
024301 2017-04-03 1000 B 44.788
024301 2017-04-03 10000 A 52.774
024301 2017-04-03 10000 B 47.719
024301 2017-04-03 30000 A 53.998
024301 2017-04-03 30000 B 51.878
024302 2017-04-03 1 A 45.234
024302 2017-04-03 1 B 40.645
024302 2017-04-03 1000 A 44.353
024302 2017-04-03 1000 B 44.788
024302 2017-04-03 10000 A 52.774
024302 2017-04-03 10000 B 47.719
024302 2017-04-03 30000 A 53.998
024302 2017-04-03 30000 B 51.878
;
run;

*isolate cycle1;
/*if you want to do this for multiple variables it may be better to
use a transpose to get the data you need*/
data cycle1;
set test;
where cycle=1 and side='A';
keep ref value;
rename value=Cycle1_Value;
run;

*sort for merge;
proc sort data=test;
by ref date cycle side;
run;

proc sort data=cycle1;
by ref;
run;

*merge data together;
data want; 
merge test cycle1;
by ref;
run;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 03 Oct 2017 17:15:27 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-10-03T17:15:27Z</dc:date>
    <item>
      <title>How to manipulate data with the same variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-manipulate-data-with-the-same-variable-values/m-p/400623#M97130</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;See the data set bellow to understand the variables I'm trying to work with&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data TEST;&lt;BR /&gt;input Ref&amp;nbsp;&amp;nbsp; &amp;nbsp;Date$&amp;nbsp;&amp;nbsp; &amp;nbsp;Cycle&amp;nbsp;&amp;nbsp; &amp;nbsp;side$&amp;nbsp;&amp;nbsp; &amp;nbsp;value;&lt;BR /&gt;datalines;&lt;BR /&gt;024301 2017-04-03 1 A 39.969&lt;BR /&gt;024301 2017-04-03 1 B 40.645&lt;BR /&gt;024301 2017-04-03 1000 A 44.353&lt;BR /&gt;024301 2017-04-03 1000 B 44.788&lt;BR /&gt;024301 2017-04-03 10000 A 52.774&lt;BR /&gt;024301 2017-04-03 10000 B 47.719&lt;BR /&gt;024301 2017-04-03 30000 A 53.998&lt;BR /&gt;024301 2017-04-03 30000 B 51.878&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have about 4000 observations. Every &lt;STRONG&gt;Ref&lt;/STRONG&gt; has 8 observations: &lt;STRONG&gt;cycle&lt;/STRONG&gt; 1 (A and B), &lt;STRONG&gt;cycle&lt;/STRONG&gt; 1000 (A and B), &lt;STRONG&gt;cycle&lt;/STRONG&gt; 10 000 (A and B) and &lt;STRONG&gt;cycle&lt;/STRONG&gt; 30 000 (A and B). Here's what I want to do for every different &lt;STRONG&gt;Ref&lt;/STRONG&gt; number (about 800 different &lt;STRONG&gt;Ref&lt;/STRONG&gt; numbers):&lt;/P&gt;&lt;P&gt;- take the &lt;STRONG&gt;Value&lt;/STRONG&gt; with &lt;STRONG&gt;cycle&lt;/STRONG&gt;= 1 and &lt;STRONG&gt;side&lt;/STRONG&gt; =A&amp;nbsp; (same for Side B) to be stored in a new variable "&lt;STRONG&gt;CYCLE1_VALUE&lt;/STRONG&gt;" beside all the other cycles with the same &lt;STRONG&gt;Ref&lt;/STRONG&gt;, same &lt;STRONG&gt;Date&lt;/STRONG&gt; and same &lt;STRONG&gt;Side&lt;/STRONG&gt;. See the table bellow for an illustration of what I want:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data WANT;&lt;BR /&gt;input Ref&amp;nbsp;&amp;nbsp; &amp;nbsp;Date$&amp;nbsp;&amp;nbsp; &amp;nbsp;Cycle&amp;nbsp;&amp;nbsp; &amp;nbsp;side$&amp;nbsp;&amp;nbsp; &amp;nbsp;value&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CYCLE1_VALUE;&lt;BR /&gt;datalines;&lt;BR /&gt;024301 2017-04-03 1 A 39.969&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt; 39.969&lt;/STRONG&gt;&lt;BR /&gt;024301 2017-04-03 1 B 40.645&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;40.645&lt;/STRONG&gt;&lt;BR /&gt;024301 2017-04-03 1000 A 44.353&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;39.969&lt;/STRONG&gt;&lt;BR /&gt;024301 2017-04-03 1000 B 44.788&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;40.645&lt;/STRONG&gt;&lt;BR /&gt;024301 2017-04-03 10000 A 52.774&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;39.969&lt;/STRONG&gt;&lt;BR /&gt;024301 2017-04-03 10000 B 47.719&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;40.645&lt;/STRONG&gt;&lt;BR /&gt;024301 2017-04-03 30000 A 53.998&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;39.969&lt;/STRONG&gt;&lt;BR /&gt;024301 2017-04-03 30000 B 51.878&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;40.645&lt;/STRONG&gt;&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to do this for the 800 different &lt;STRONG&gt;Ref &lt;/STRONG&gt;numbers... There are no regularities in the ref numbers, unfortunately...&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will need to do easy math after that! How can I do that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Marie-Christine&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2017 15:47:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-manipulate-data-with-the-same-variable-values/m-p/400623#M97130</guid>
      <dc:creator>bemariec</dc:creator>
      <dc:date>2017-10-03T15:47:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to manipulate data with the same variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-manipulate-data-with-the-same-variable-values/m-p/400634#M97134</link>
      <description>&lt;P&gt;Can you describe what your are going to do "in the easy math" afterwards? It may be that there is much easier approach or at least more straightforward.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Quite often an approach that manipulates data in the manner you are showing is following an approach developed from something like Excel because of the limitations of spreadsheets and tools in SAS provide considerably different ways to summarize and combine data&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2017 16:05:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-manipulate-data-with-the-same-variable-values/m-p/400634#M97134</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-03T16:05:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to manipulate data with the same variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-manipulate-data-with-the-same-variable-values/m-p/400648#M97139</link>
      <description>&lt;P&gt;It looks very much similar to the following algorithm:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[1] If Cycle = 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if side = A then holdA_Value = A_Value; Cycle1_Value = holdA_Value;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else if side = B then holdB = B_Value; Cycle1_Value = holdB_Value;&lt;/P&gt;
&lt;P&gt;[2] If Cycle ^= 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if side = A&amp;nbsp; then Cycle1_Value = holdA_Value;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if side = B then Cycle1_Value = holdB_Value;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2017 16:38:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-manipulate-data-with-the-same-variable-values/m-p/400648#M97139</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2017-10-03T16:38:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to manipulate data with the same variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-manipulate-data-with-the-same-variable-values/m-p/400649#M97140</link>
      <description>I want to do a substraction between Value and Value at cycle 1 for every Ref, this will by the variable that I will work with to do mean and standard deviation</description>
      <pubDate>Tue, 03 Oct 2017 16:38:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-manipulate-data-with-the-same-variable-values/m-p/400649#M97140</guid>
      <dc:creator>bemariec</dc:creator>
      <dc:date>2017-10-03T16:38:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to manipulate data with the same variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-manipulate-data-with-the-same-variable-values/m-p/400651#M97141</link>
      <description>&lt;P&gt;When you post, you should have thought everything. Do not change the specs afterwards. Time is precious to everyone.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2017 16:42:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-manipulate-data-with-the-same-variable-values/m-p/400651#M97141</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2017-10-03T16:42:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to manipulate data with the same variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-manipulate-data-with-the-same-variable-values/m-p/400654#M97142</link>
      <description>I'm sorry ,I was answering to ballardw... I have not change anything... ?</description>
      <pubDate>Tue, 03 Oct 2017 16:45:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-manipulate-data-with-the-same-variable-values/m-p/400654#M97142</guid>
      <dc:creator>bemariec</dc:creator>
      <dc:date>2017-10-03T16:45:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to manipulate data with the same variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-manipulate-data-with-the-same-variable-values/m-p/400657#M97143</link>
      <description>&lt;P&gt;I agree with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; that knowing where you ultimately want to go woudl help in finding you the best solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the meantime, if you do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TEST;
input Ref    Date:yymmdd10.    Cycle    side$    value;
datalines;
024301 2017-04-03 1 A 39.969
024301 2017-04-03 1 B 40.645
024301 2017-04-03 1000 A 44.353
024301 2017-04-03 1000 B 44.788
024301 2017-04-03 10000 A 52.774
024301 2017-04-03 10000 B 47.719
024301 2017-04-03 30000 A 53.998
024301 2017-04-03 30000 B 51.878
;
run;

proc sql;
	create table populated as
	select c.ref, c.date, c.cycle, c.side, c.value as myval, d.value as fixval
	from test c inner join test d
	on c.ref = d.ref and c.date = d.date and c.side = d.side
	where d.cycle = 1;
quit; 

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You get this:&lt;/P&gt;
&lt;PRE&gt;The SAS System					
					
Ref	Date	Cycle	side	myval	fixval
24301	20912	1	A	39.969	39.969
24301	20912	1	B	40.645	40.645
24301	20912	1000	A	44.353	39.969
24301	20912	1000	B	44.788	40.645
24301	20912	10000	A	52.774	39.969
24301	20912	10000	B	47.719	40.645
24301	20912	30000	A	53.998	39.969
24301	20912	30000	B	51.878	40.645
&lt;/PRE&gt;
&lt;P&gt;But as noted, that may not really be the way you want to go.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2017 16:58:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-manipulate-data-with-the-same-variable-values/m-p/400657#M97143</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2017-10-03T16:58:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to manipulate data with the same variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-manipulate-data-with-the-same-variable-values/m-p/400672#M97145</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/154111"&gt;@bemariec&lt;/a&gt;&amp;nbsp;your sample data is bad. If you have multiple REF and that's important you should include sample data with multiple REFs so we can replicate your situation. I've made some assumptions and replicated your REF to create at least two in my data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*sample data;
data TEST;
input Ref    Date$    Cycle    side$    value;
datalines;
024301 2017-04-03 1 A 39.969
024301 2017-04-03 1 B 40.645
024301 2017-04-03 1000 A 44.353
024301 2017-04-03 1000 B 44.788
024301 2017-04-03 10000 A 52.774
024301 2017-04-03 10000 B 47.719
024301 2017-04-03 30000 A 53.998
024301 2017-04-03 30000 B 51.878
024302 2017-04-03 1 A 45.234
024302 2017-04-03 1 B 40.645
024302 2017-04-03 1000 A 44.353
024302 2017-04-03 1000 B 44.788
024302 2017-04-03 10000 A 52.774
024302 2017-04-03 10000 B 47.719
024302 2017-04-03 30000 A 53.998
024302 2017-04-03 30000 B 51.878
;
run;

*isolate cycle1;
/*if you want to do this for multiple variables it may be better to
use a transpose to get the data you need*/
data cycle1;
set test;
where cycle=1 and side='A';
keep ref value;
rename value=Cycle1_Value;
run;

*sort for merge;
proc sort data=test;
by ref date cycle side;
run;

proc sort data=cycle1;
by ref;
run;

*merge data together;
data want; 
merge test cycle1;
by ref;
run;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Oct 2017 17:15:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-manipulate-data-with-the-same-variable-values/m-p/400672#M97145</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-03T17:15:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to manipulate data with the same variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-manipulate-data-with-the-same-variable-values/m-p/400680#M97146</link>
      <description>Thank you!!! It works!&lt;BR /&gt;</description>
      <pubDate>Tue, 03 Oct 2017 17:38:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-manipulate-data-with-the-same-variable-values/m-p/400680#M97146</guid>
      <dc:creator>bemariec</dc:creator>
      <dc:date>2017-10-03T17:38:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to manipulate data with the same variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-manipulate-data-with-the-same-variable-values/m-p/400684#M97148</link>
      <description>Thanks! it works to!!</description>
      <pubDate>Tue, 03 Oct 2017 17:50:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-manipulate-data-with-the-same-variable-values/m-p/400684#M97148</guid>
      <dc:creator>bemariec</dc:creator>
      <dc:date>2017-10-03T17:50:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to manipulate data with the same variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-manipulate-data-with-the-same-variable-values/m-p/400753#M97156</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/154111"&gt;@bemariec&lt;/a&gt; wrote:&lt;BR /&gt;I want to do a substraction between Value and Value at cycle 1 for every Ref, this will by the variable that I will work with to do mean and standard deviation&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;By any chance does this represent that difference?&lt;/P&gt;
&lt;PRE&gt;data want;
   set test;
   lc=lag(cycle);
   dv=dif(value);
   if cycle=lc then Cycledif = dv;
   drop lc dv;
run;&lt;/PRE&gt;
&lt;P&gt;Then proc means with cycle as a class variable and dv as the var?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2017 19:33:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-manipulate-data-with-the-same-variable-values/m-p/400753#M97156</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-03T19:33:50Z</dc:date>
    </item>
  </channel>
</rss>

