<?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: new column in dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/new-column-in-dataset/m-p/14914#M1916</link>
    <description>Thank you for your answer but I do not think this is the case.&lt;BR /&gt;
&lt;BR /&gt;
I want to have something like this:&lt;BR /&gt;
&lt;BR /&gt;
for i=1 to 4;&lt;BR /&gt;
do:&lt;BR /&gt;
 c{i}=b{i+1};&lt;BR /&gt;
end;&lt;BR /&gt;
c{5}=0 (or missing).&lt;BR /&gt;
&lt;BR /&gt;
or  something like this:&lt;BR /&gt;
&lt;BR /&gt;
if a=1 then c=b where a=2;&lt;BR /&gt;
and so on..&lt;BR /&gt;
&lt;BR /&gt;
I do not know haw to do this based on the existing dataset.&lt;BR /&gt;
&lt;BR /&gt;
In my dataset I have this example repeated many times. So  var.a is not an observation number.&lt;BR /&gt;
&lt;BR /&gt;
Thanks.</description>
    <pubDate>Thu, 02 Apr 2009 19:59:10 GMT</pubDate>
    <dc:creator>Lidia</dc:creator>
    <dc:date>2009-04-02T19:59:10Z</dc:date>
    <item>
      <title>new column in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/new-column-in-dataset/m-p/14912#M1914</link>
      <description>I need to create new column in my data set.  All values in it should be shifted up by 1 cell in comparison with other column.&lt;BR /&gt;
&lt;BR /&gt;
Let say I have:&lt;BR /&gt;
a b&lt;BR /&gt;
1 23&lt;BR /&gt;
2 15&lt;BR /&gt;
3 45&lt;BR /&gt;
4 55&lt;BR /&gt;
5 67&lt;BR /&gt;
 I need to add the column c such as:&lt;BR /&gt;
a b     c&lt;BR /&gt;
1 23   15&lt;BR /&gt;
2 15   45&lt;BR /&gt;
3 45   55&lt;BR /&gt;
4 55   67&lt;BR /&gt;
5 67    0&lt;BR /&gt;
&lt;BR /&gt;
What I should do in this case?&lt;BR /&gt;
&lt;BR /&gt;
Thanks a lot!</description>
      <pubDate>Thu, 02 Apr 2009 19:07:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/new-column-in-dataset/m-p/14912#M1914</guid>
      <dc:creator>Lidia</dc:creator>
      <dc:date>2009-04-02T19:07:44Z</dc:date>
    </item>
    <item>
      <title>Re: new column in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/new-column-in-dataset/m-p/14913#M1915</link>
      <description>It appears as if your a variable defines the order of the observations.  If this is the case I would sort the data in descending order of A and then use the lag function in a data step to lag the first obs to the second, second to third etc.&lt;BR /&gt;
&lt;BR /&gt;
If A does not define the order of the observations I would probably create a variable based on the obs number in a data step first (use the  _n_  variable)&lt;BR /&gt;
&lt;BR /&gt;
Let me know if you need further explantion&lt;BR /&gt;
&lt;BR /&gt;
Linda&lt;BR /&gt;
&lt;BR /&gt;
Data one;&lt;BR /&gt;
  input a b;&lt;BR /&gt;
  obsnum= _n_;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort ; by descending obsnum;&lt;BR /&gt;
&lt;BR /&gt;
data two;&lt;BR /&gt;
  set one;&lt;BR /&gt;
  newcol = lag(b);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data = two; by obsnum;  *  this gets in back in the original order;</description>
      <pubDate>Thu, 02 Apr 2009 19:37:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/new-column-in-dataset/m-p/14913#M1915</guid>
      <dc:creator>LAP</dc:creator>
      <dc:date>2009-04-02T19:37:02Z</dc:date>
    </item>
    <item>
      <title>Re: new column in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/new-column-in-dataset/m-p/14914#M1916</link>
      <description>Thank you for your answer but I do not think this is the case.&lt;BR /&gt;
&lt;BR /&gt;
I want to have something like this:&lt;BR /&gt;
&lt;BR /&gt;
for i=1 to 4;&lt;BR /&gt;
do:&lt;BR /&gt;
 c{i}=b{i+1};&lt;BR /&gt;
end;&lt;BR /&gt;
c{5}=0 (or missing).&lt;BR /&gt;
&lt;BR /&gt;
or  something like this:&lt;BR /&gt;
&lt;BR /&gt;
if a=1 then c=b where a=2;&lt;BR /&gt;
and so on..&lt;BR /&gt;
&lt;BR /&gt;
I do not know haw to do this based on the existing dataset.&lt;BR /&gt;
&lt;BR /&gt;
In my dataset I have this example repeated many times. So  var.a is not an observation number.&lt;BR /&gt;
&lt;BR /&gt;
Thanks.</description>
      <pubDate>Thu, 02 Apr 2009 19:59:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/new-column-in-dataset/m-p/14914#M1916</guid>
      <dc:creator>Lidia</dc:creator>
      <dc:date>2009-04-02T19:59:10Z</dc:date>
    </item>
    <item>
      <title>Re: new column in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/new-column-in-dataset/m-p/14915#M1917</link>
      <description>Here's one way:&lt;BR /&gt;
&lt;BR /&gt;
=====&lt;BR /&gt;
data test;&lt;BR /&gt;
   input a b;&lt;BR /&gt;
cards4;&lt;BR /&gt;
1 23&lt;BR /&gt;
2 15&lt;BR /&gt;
3 45&lt;BR /&gt;
4 55&lt;BR /&gt;
5 67&lt;BR /&gt;
;;;;&lt;BR /&gt;
&lt;BR /&gt;
options mergenoby=nowarn;&lt;BR /&gt;
data new;&lt;BR /&gt;
   retain a b c;&lt;BR /&gt;
   merge test&lt;BR /&gt;
         test (keep=b rename=(b=c) firstobs=2)&lt;BR /&gt;
         end=eod;&lt;BR /&gt;
   if eod then &lt;BR /&gt;
      c = 0;&lt;BR /&gt;
run;&lt;BR /&gt;
options mergenoby=error;&lt;BR /&gt;
&lt;BR /&gt;
proc print;&lt;BR /&gt;
run;&lt;BR /&gt;
=====&lt;BR /&gt;
&lt;BR /&gt;
Sorry about the lack of indentation - the forum software doesn't preserve it.</description>
      <pubDate>Thu, 02 Apr 2009 20:45:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/new-column-in-dataset/m-p/14915#M1917</guid>
      <dc:creator>JackHamilton</dc:creator>
      <dc:date>2009-04-02T20:45:09Z</dc:date>
    </item>
    <item>
      <title>Re: new column in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/new-column-in-dataset/m-p/14916#M1918</link>
      <description>Your code in the last post does not really make sense... My interpretation of your question is that LAP solved it for you. Since have no variable which naturally holds the order, it is created temporarily (obsnum). Please read his/hers post again more carefully.&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Linus</description>
      <pubDate>Thu, 02 Apr 2009 20:45:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/new-column-in-dataset/m-p/14916#M1918</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2009-04-02T20:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: new column in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/new-column-in-dataset/m-p/14917#M1919</link>
      <description>I don't see a need for the two sorts in LAP's code.</description>
      <pubDate>Thu, 02 Apr 2009 20:57:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/new-column-in-dataset/m-p/14917#M1919</guid>
      <dc:creator>JackHamilton</dc:creator>
      <dc:date>2009-04-02T20:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: new column in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/new-column-in-dataset/m-p/14918#M1920</link>
      <description>Hi guys.&lt;BR /&gt;
&lt;BR /&gt;
Here's another solution.&lt;BR /&gt;
&lt;BR /&gt;
If your not concerned about the final order of the rows, try this:&lt;BR /&gt;
&lt;BR /&gt;
data OUT;&lt;BR /&gt;
set IN (firstobs=2) end=_EOF ; /* first set starts at 2nd row */&lt;BR /&gt;
if _EOF then do; /* deals with last row */&lt;BR /&gt;
C=0;&lt;BR /&gt;
output; &lt;BR /&gt;
end;&lt;BR /&gt;
C=B; /* stores value of B into C */&lt;BR /&gt;
set IN; /* second set starts at 1st row */&lt;BR /&gt;
output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
this results in:&lt;BR /&gt;
&lt;BR /&gt;
a b c&lt;BR /&gt;
1 23 15&lt;BR /&gt;
2 15 45&lt;BR /&gt;
3 45 55&lt;BR /&gt;
5 67 0&lt;BR /&gt;
4 55 67&lt;BR /&gt;
&lt;BR /&gt;
result is as expected, but the last row positions is switched with the previous.&lt;BR /&gt;
&lt;BR /&gt;
Greetings from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos at &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;</description>
      <pubDate>Fri, 03 Apr 2009 10:18:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/new-column-in-dataset/m-p/14918#M1920</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-04-03T10:18:33Z</dc:date>
    </item>
    <item>
      <title>Re: new column in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/new-column-in-dataset/m-p/14919#M1921</link>
      <description>Hi guys! &lt;BR /&gt;
&lt;BR /&gt;
Thank you all for your advise. You gave me some idea haw to deal with it.&lt;BR /&gt;
&lt;BR /&gt;
Lidia</description>
      <pubDate>Fri, 03 Apr 2009 12:34:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/new-column-in-dataset/m-p/14919#M1921</guid>
      <dc:creator>Lidia</dc:creator>
      <dc:date>2009-04-03T12:34:10Z</dc:date>
    </item>
    <item>
      <title>Re: new column in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/new-column-in-dataset/m-p/14920#M1922</link>
      <description>The following will do it:&lt;BR /&gt;
&lt;BR /&gt;
data test;&lt;BR /&gt;
input a b;&lt;BR /&gt;
cards;&lt;BR /&gt;
1 23&lt;BR /&gt;
2 15&lt;BR /&gt;
3 45&lt;BR /&gt;
4 55&lt;BR /&gt;
5 67&lt;BR /&gt;
;;;;&lt;BR /&gt;
&lt;BR /&gt;
data lastzero;&lt;BR /&gt;
input a b;&lt;BR /&gt;
cards;&lt;BR /&gt;
0 0&lt;BR /&gt;
;;;;&lt;BR /&gt;
&lt;BR /&gt;
data test2;&lt;BR /&gt;
   set test lastzero;&lt;BR /&gt;
   aprime=lag(a);&lt;BR /&gt;
   bprime=lag(b);&lt;BR /&gt;
   cprime=b;&lt;BR /&gt;
&lt;BR /&gt;
   if aprime ne . ;&lt;BR /&gt;
&lt;BR /&gt;
   drop a b;&lt;BR /&gt;
   rename aprime=a bprime=b cprime=c;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Kevin</description>
      <pubDate>Fri, 03 Apr 2009 14:49:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/new-column-in-dataset/m-p/14920#M1922</guid>
      <dc:creator>genkiboy</dc:creator>
      <dc:date>2009-04-03T14:49:13Z</dc:date>
    </item>
    <item>
      <title>Re: new column in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/new-column-in-dataset/m-p/14921#M1923</link>
      <description>Hi,&lt;BR /&gt;
Again. Thanks a lot. I used this lag() function. I did not now that this function exists before. I tried to search “help” for some function to do my task. I used wrong keywords all the times. With this function it took me 5 sec. to calculate what I need.&lt;BR /&gt;
&lt;BR /&gt;
Now I am wandering if it is possible to find a list of all functions SAS can use? Well , of course there are thousands of them but one can scroll down thought the list and find the appropriate function he/she needs.</description>
      <pubDate>Mon, 06 Apr 2009 15:13:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/new-column-in-dataset/m-p/14921#M1923</guid>
      <dc:creator>Lidia</dc:creator>
      <dc:date>2009-04-06T15:13:20Z</dc:date>
    </item>
    <item>
      <title>Re: new column in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/new-column-in-dataset/m-p/14922#M1924</link>
      <description>The SAS system's "Help and Documentation" (F1 key) has a keyword reference for "functions, by category".&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Mon, 06 Apr 2009 16:42:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/new-column-in-dataset/m-p/14922#M1924</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-04-06T16:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: new column in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/new-column-in-dataset/m-p/14923#M1925</link>
      <description>Thank you Scott! I found it.</description>
      <pubDate>Mon, 06 Apr 2009 18:44:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/new-column-in-dataset/m-p/14923#M1925</guid>
      <dc:creator>Lidia</dc:creator>
      <dc:date>2009-04-06T18:44:54Z</dc:date>
    </item>
  </channel>
</rss>

