<?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 iteration of the first value in a group of observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/iteration-of-the-first-value-in-a-group-of-observations/m-p/436564#M108580</link>
    <description>&lt;P&gt;Hi and thank you so much for helping me with my previous question. I would really appreciate if you could please help me with this one too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set with multiple observations for each ID. I want to keep the baseline value for education variable. How can I iterate the first value for the variable "education" in all the observations for each caseid (by caseid).&amp;nbsp;Hereunder, I have included what_I_Have and What_I_Want datalines.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data what_I_Have;&lt;BR /&gt;input id visit education;&lt;BR /&gt;datalines;&lt;BR /&gt;1000 1 1&lt;BR /&gt;1000 2 1&lt;BR /&gt;1000 3 2&lt;BR /&gt;1000 4 1&lt;BR /&gt;1001 1 .&lt;BR /&gt;1001 2 1&lt;BR /&gt;1001 3 2&lt;BR /&gt;1002 1 2&lt;BR /&gt;1002 2 1&lt;BR /&gt;1003 1 1&lt;BR /&gt;1003 2 2&lt;BR /&gt;1003 3 2&lt;BR /&gt;1003 4 2&lt;BR /&gt;1004 1 .&lt;BR /&gt;1004 2 1&lt;BR /&gt;1004 3 1&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;&lt;SPAN&gt;data what_I_Have;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;input id visit education;&lt;/SPAN&gt;&lt;BR /&gt;datalines&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1000 1 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1000 2 1&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1000 3 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1000 4 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1001 1 .&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1001&amp;nbsp;&lt;/SPAN&gt;2 .&lt;BR /&gt;&lt;SPAN&gt;1001 3 .&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1002 1 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1002 2 2&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1003 1 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1003 2 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1003 3 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1003 4 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1004&amp;nbsp;&lt;/SPAN&gt;1 .&lt;BR /&gt;&lt;SPAN&gt;1004 2 .&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1004 3 .&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you so much for your help.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 13 Feb 2018 03:56:08 GMT</pubDate>
    <dc:creator>Sinakian1</dc:creator>
    <dc:date>2018-02-13T03:56:08Z</dc:date>
    <item>
      <title>iteration of the first value in a group of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/iteration-of-the-first-value-in-a-group-of-observations/m-p/436564#M108580</link>
      <description>&lt;P&gt;Hi and thank you so much for helping me with my previous question. I would really appreciate if you could please help me with this one too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set with multiple observations for each ID. I want to keep the baseline value for education variable. How can I iterate the first value for the variable "education" in all the observations for each caseid (by caseid).&amp;nbsp;Hereunder, I have included what_I_Have and What_I_Want datalines.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data what_I_Have;&lt;BR /&gt;input id visit education;&lt;BR /&gt;datalines;&lt;BR /&gt;1000 1 1&lt;BR /&gt;1000 2 1&lt;BR /&gt;1000 3 2&lt;BR /&gt;1000 4 1&lt;BR /&gt;1001 1 .&lt;BR /&gt;1001 2 1&lt;BR /&gt;1001 3 2&lt;BR /&gt;1002 1 2&lt;BR /&gt;1002 2 1&lt;BR /&gt;1003 1 1&lt;BR /&gt;1003 2 2&lt;BR /&gt;1003 3 2&lt;BR /&gt;1003 4 2&lt;BR /&gt;1004 1 .&lt;BR /&gt;1004 2 1&lt;BR /&gt;1004 3 1&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;&lt;SPAN&gt;data what_I_Have;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;input id visit education;&lt;/SPAN&gt;&lt;BR /&gt;datalines&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1000 1 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1000 2 1&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1000 3 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1000 4 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1001 1 .&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1001&amp;nbsp;&lt;/SPAN&gt;2 .&lt;BR /&gt;&lt;SPAN&gt;1001 3 .&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1002 1 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1002 2 2&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1003 1 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1003 2 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1003 3 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1003 4 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1004&amp;nbsp;&lt;/SPAN&gt;1 .&lt;BR /&gt;&lt;SPAN&gt;1004 2 .&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1004 3 .&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you so much for your help.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2018 03:56:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/iteration-of-the-first-value-in-a-group-of-observations/m-p/436564#M108580</guid>
      <dc:creator>Sinakian1</dc:creator>
      <dc:date>2018-02-13T03:56:08Z</dc:date>
    </item>
    <item>
      <title>Re: iteration of the first value in a group of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/iteration-of-the-first-value-in-a-group-of-observations/m-p/436570#M108583</link>
      <description>&lt;P&gt;You need:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;BY, &amp;nbsp;This assumes your data is sorted by ID&lt;/LI&gt;
&lt;LI&gt;RETAIN to hold the value across rows&lt;/LI&gt;
&lt;LI&gt;FIRST to identify the first record. In your case you could also use VISIT=1&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;

by id;

RETAIN education_baseline;

if first.id then education_baseline=education;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Feb 2018 04:19:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/iteration-of-the-first-value-in-a-group-of-observations/m-p/436570#M108583</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-13T04:19:37Z</dc:date>
    </item>
    <item>
      <title>Re: iteration of the first value in a group of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/iteration-of-the-first-value-in-a-group-of-observations/m-p/436599#M108599</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data what_I_Have;
input id visit education;
datalines;
1000 1 1
1000 2 1
1000 3 2
1000 4 1
1001 1 .
1001 2 1
1001 3 2
1002 1 2
1002 2 1
1003 1 1
1003 2 2
1003 3 2
1003 4 2
1004 1 .
1004 2 1
1004 3 1
;
run;

proc sort data=what_I_Have; 
by id visit;
run;

data what_I_Want(rename=(education1=education));
set what_I_Have;
by id visit;
retain education1;
if first.id then education1=education;
drop education;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Please Let us know if it worked for you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2018 08:13:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/iteration-of-the-first-value-in-a-group-of-observations/m-p/436599#M108599</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2018-02-13T08:13:39Z</dc:date>
    </item>
  </channel>
</rss>

