<?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: Please help!!!! in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Please-help/m-p/57522#M12407</link>
    <description>[pre]&lt;BR /&gt;
data a;&lt;BR /&gt;
A='101';order=1;val=25;p=0;output;&lt;BR /&gt;
A='101';order=2;val=54;p=0;output;&lt;BR /&gt;
A='101';order=3;val=66;p=1;output;&lt;BR /&gt;
A='101';order=4;val=85;p=1;output;&lt;BR /&gt;
A='101';order=5;val=99;p=0;output;&lt;BR /&gt;
A='101';order=6;val=120;p=0;output;&lt;BR /&gt;
A='101';order=7;val=135;p=1;output;&lt;BR /&gt;
A='101';order=8;val=170;p=1;output;&lt;BR /&gt;
A='101';order=9;val=186;p=1;output;&lt;BR /&gt;
A='101';order=10;val=190;p=1;output;&lt;BR /&gt;
A='101';order=11;val=195;p=1;output;&lt;BR /&gt;
run;&lt;BR /&gt;
data temp;&lt;BR /&gt;
 set a;&lt;BR /&gt;
 retain flag 0;&lt;BR /&gt;
 if p ne lag(p) then flag+1;&lt;BR /&gt;
run;&lt;BR /&gt;
data result;&lt;BR /&gt;
 set temp;&lt;BR /&gt;
  by flag;&lt;BR /&gt;
  retain pre;&lt;BR /&gt;
  if first.flag then pre=val;&lt;BR /&gt;
  if last.flag and p then do;&lt;BR /&gt;
                           Name='A';&lt;BR /&gt;
						   Diff=catx('-',val,pre);&lt;BR /&gt;
						   output;&lt;BR /&gt;
						   end;&lt;BR /&gt;
  keep Name Diff;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
    <pubDate>Fri, 30 Jul 2010 12:45:26 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2010-07-30T12:45:26Z</dc:date>
    <item>
      <title>Please help!!!!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Please-help/m-p/57520#M12405</link>
      <description>Hello all,&lt;BR /&gt;
&lt;BR /&gt;
I'm new to this forum. the data is like this:&lt;BR /&gt;
&lt;BR /&gt;
data a;&lt;BR /&gt;
A='101';order=1;val=25;p=0;output;&lt;BR /&gt;
A='101';order=2;val=54;p=0;output;&lt;BR /&gt;
A='101';order=3;val=66;p=1;output;&lt;BR /&gt;
A='101';order=4;val=85;p=1;output;&lt;BR /&gt;
A='101';order=5;val=99;p=0;output;&lt;BR /&gt;
A='101';order=6;val=120;p=0;output;&lt;BR /&gt;
A='101';order=7;val=135;p=1;output;&lt;BR /&gt;
A='101';order=8;val=170;p=1;output;&lt;BR /&gt;
A='101';order=9;val=186;p=1;output;&lt;BR /&gt;
A='101';order=10;val=190;p=1;output;&lt;BR /&gt;
A='101';order=11;val=195;p=1;output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
I've to calculate the difference of two consecutive p=1 i.e., output should have 2 obs with difference of first p=1 and last p=1. Please help.&lt;BR /&gt;
Name    Diff&lt;BR /&gt;
A          85-66&lt;BR /&gt;
A          195-135</description>
      <pubDate>Thu, 29 Jul 2010 15:00:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Please-help/m-p/57520#M12405</guid>
      <dc:creator>Hellomeitis</dc:creator>
      <dc:date>2010-07-29T15:00:40Z</dc:date>
    </item>
    <item>
      <title>Re: Please help!!!!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Please-help/m-p/57521#M12406</link>
      <description>Assuming I understand the question, consider the following DATA step:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
Data diff;&lt;BR /&gt;
   set a;&lt;BR /&gt;
   if p=0 then cnt=0;&lt;BR /&gt;
   cnt+p;&lt;BR /&gt;
   lastv=lag(val);&lt;BR /&gt;
   if cnt ge 2 then diff = val - lastv;&lt;BR /&gt;
   output;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 29 Jul 2010 17:58:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Please-help/m-p/57521#M12406</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2010-07-29T17:58:25Z</dc:date>
    </item>
    <item>
      <title>Re: Please help!!!!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Please-help/m-p/57522#M12407</link>
      <description>[pre]&lt;BR /&gt;
data a;&lt;BR /&gt;
A='101';order=1;val=25;p=0;output;&lt;BR /&gt;
A='101';order=2;val=54;p=0;output;&lt;BR /&gt;
A='101';order=3;val=66;p=1;output;&lt;BR /&gt;
A='101';order=4;val=85;p=1;output;&lt;BR /&gt;
A='101';order=5;val=99;p=0;output;&lt;BR /&gt;
A='101';order=6;val=120;p=0;output;&lt;BR /&gt;
A='101';order=7;val=135;p=1;output;&lt;BR /&gt;
A='101';order=8;val=170;p=1;output;&lt;BR /&gt;
A='101';order=9;val=186;p=1;output;&lt;BR /&gt;
A='101';order=10;val=190;p=1;output;&lt;BR /&gt;
A='101';order=11;val=195;p=1;output;&lt;BR /&gt;
run;&lt;BR /&gt;
data temp;&lt;BR /&gt;
 set a;&lt;BR /&gt;
 retain flag 0;&lt;BR /&gt;
 if p ne lag(p) then flag+1;&lt;BR /&gt;
run;&lt;BR /&gt;
data result;&lt;BR /&gt;
 set temp;&lt;BR /&gt;
  by flag;&lt;BR /&gt;
  retain pre;&lt;BR /&gt;
  if first.flag then pre=val;&lt;BR /&gt;
  if last.flag and p then do;&lt;BR /&gt;
                           Name='A';&lt;BR /&gt;
						   Diff=catx('-',val,pre);&lt;BR /&gt;
						   output;&lt;BR /&gt;
						   end;&lt;BR /&gt;
  keep Name Diff;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Fri, 30 Jul 2010 12:45:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Please-help/m-p/57522#M12407</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-07-30T12:45:26Z</dc:date>
    </item>
  </channel>
</rss>

