<?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: Analyzing Data Using Long form dataset (multiple observations for each participant) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Analyzing-Data-Using-Long-form-dataset-multiple-observations-for/m-p/779548#M248295</link>
    <description>&lt;PRE&gt;data have;
input StudyID     Visit   Marriage $ Age  ;
cards;
104                  1                        .                        8                                   .
104                  2                          Yes                             9                                    Yes
104                  3                           No                             .                          No
105                  1                           .                     .                          .
105                  2                           .                      .                          .
105                  3                          Yes                              10                                    Yes
106                  1                          .                        .                        .
106                  2                           Yes                             9                                      No
106                  3                           No                              10  
;

data first_Marriage;
 set have(where=(Marriage is not missing));
 by StudyID;
if first.StudyID;
keep StudyID Visit Marriage;
run;&lt;/PRE&gt;</description>
    <pubDate>Wed, 10 Nov 2021 12:35:03 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2021-11-10T12:35:03Z</dc:date>
    <item>
      <title>Analyzing Data Using Long form dataset (multiple observations for each participant)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Analyzing-Data-Using-Long-form-dataset-multiple-observations-for/m-p/779491#M248260</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am working with a long form dataset, meaning that there are multiple observations per participant (because of multiple visits). I was trying to think of code that will allow me to include the first non missing value for each variable. For example, I want to get the first non missing value for for marital satisfaction and number of children seen per month. If the data was missing for the first visit, I would want the data from the second visit, if not then third visit and so on. Any suggestions for the most efficient way to go about doing this?&amp;nbsp; Thank you in advance for all your help!&lt;/P&gt;</description>
      <pubDate>Wed, 10 Nov 2021 02:56:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Analyzing-Data-Using-Long-form-dataset-multiple-observations-for/m-p/779491#M248260</guid>
      <dc:creator>zaldarsa</dc:creator>
      <dc:date>2021-11-10T02:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: Analyzing Data Using Long form dataset (multiple observations for each participant)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Analyzing-Data-Using-Long-form-dataset-multiple-observations-for/m-p/779493#M248262</link>
      <description>Can you provide some example data, fake data is fine, then we can assist you further. &lt;BR /&gt;Retain is one method, update may be another, but I suspect there are some variables that may need other logic, such as age which may need a first or last?</description>
      <pubDate>Wed, 10 Nov 2021 03:07:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Analyzing-Data-Using-Long-form-dataset-multiple-observations-for/m-p/779493#M248262</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-11-10T03:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: Analyzing Data Using Long form dataset (multiple observations for each participant)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Analyzing-Data-Using-Long-form-dataset-multiple-observations-for/m-p/779499#M248264</link>
      <description>&lt;P&gt;Sure. For example, say this was my dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Study ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Visit #&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Marriage Satisfaction&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Age&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Have Close Friends?&lt;/P&gt;&lt;P&gt;104&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Missing&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Missing&lt;/P&gt;&lt;P&gt;104&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Yes&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Yes&lt;/P&gt;&lt;P&gt;104&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;No&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Missing&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; No&lt;/P&gt;&lt;P&gt;105&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Missing&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Missing&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Missing&lt;/P&gt;&lt;P&gt;105&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Missing&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Missing&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Missing&lt;/P&gt;&lt;P&gt;105&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Yes&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Yes&lt;/P&gt;&lt;P&gt;106&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Missing&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Missing&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Missing&lt;/P&gt;&lt;P&gt;106&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Yes&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; No&lt;/P&gt;&lt;P&gt;106&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;No&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Yes&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I would want to create a code the would give me the first non-missing value of these variables for each ID. For example, for ID 104 that would be visit 2 for marriage, visit 1 for age, visit 2 for having close friends.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Nov 2021 04:56:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Analyzing-Data-Using-Long-form-dataset-multiple-observations-for/m-p/779499#M248264</guid>
      <dc:creator>zaldarsa</dc:creator>
      <dc:date>2021-11-10T04:56:25Z</dc:date>
    </item>
    <item>
      <title>Re: Analyzing Data Using Long form dataset (multiple observations for each participant)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Analyzing-Data-Using-Long-form-dataset-multiple-observations-for/m-p/779528#M248283</link>
      <description>&lt;P&gt;You will get better and quicker answers if you show your sample data as a data step, e.g. like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options missing=' ';                              
data have;                                        
  infile cards dsd delimiter=',' missover;        
  length                                          
    Study_ID 8                                    
    Visit_no 8                                    
    Marriage_satisfaction $3                      
    Age 8                                         
    Close_friends $3                              
    ;                                             
  input Study_ID--Close_friends;                  
cards;                                            
104,1,,8,,                                        
104,2,Yes,9,Yes,                                  
104,3,No,,No,                                     
105,1,,,,                                         
105,2,,,,                                         
105,3,Yes,10,Yes,                                 
106,1,,,,                                         
106,2,Yes,9,No,                                   
106,3,No,10,Yes,                                  
;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The problem you have can be solved with an update in place solution. But first you may want to copy your input dataset to the output dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;   
  set have;  
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can update the WANT dataset like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;                                            
  length                                              
    _Marriage_satisfaction $3                         
    _Age 8                                            
    _Close_friends $3                                 
    ;                                                 
  do _N_=nobs to 1 by -1;                             
    modify want point=_N_ nobs=nobs;                  
    first_ID=Study_ID ne lag(Study_ID);               
    if not first_ID then do;                          
      if missing(Marriage_satisfaction) then          
        Marriage_satisfaction=_Marriage_satisfaction; 
      if missing(age) then                            
        age=_age;                                     
      if missing(Close_friends) then                  
        Close_friends=_Close_friends;                 
      replace;                                        
      end;                                            
    _Marriage_satisfaction=Marriage_satisfaction;     
    _age=age;                                         
    _Close_friends=Close_friends;                     
    end;                                              
  stop;                                               
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So the basic idea is to run through the dataset backwards, and store the values to be updated in temporary variables (after getting the previous value if missing).&lt;/P&gt;</description>
      <pubDate>Wed, 10 Nov 2021 10:26:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Analyzing-Data-Using-Long-form-dataset-multiple-observations-for/m-p/779528#M248283</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2021-11-10T10:26:12Z</dc:date>
    </item>
    <item>
      <title>Re: Analyzing Data Using Long form dataset (multiple observations for each participant)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Analyzing-Data-Using-Long-form-dataset-multiple-observations-for/m-p/779547#M248294</link>
      <description>&lt;P&gt;Thanks at &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt; for providing data in usable form &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;retain + coalesce(c) could be used:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   by Study_ID;

   length 
      _Marriage_satisfaction $ 3
      _Age 8
      _Close_friends $ 3
   ;

   retain _:;

   if first.Study_ID then do;
      call missing(of _:);
   end;

   _Marriage_satisfaction = coalescec(_Marriage_satisfaction, Marriage_satisfaction);
   _Age = coalesce(_Age, Age);
   _Close_friends = coalescec(_Close_friends, Close_friends);

   if last.Study_ID then do;
      Marriage_satisfaction = _Marriage_satisfaction;
      Age = _Age;
      Close_friends = _Close_friends;

      output;
   end;

   drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Nov 2021 12:35:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Analyzing-Data-Using-Long-form-dataset-multiple-observations-for/m-p/779547#M248294</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-11-10T12:35:02Z</dc:date>
    </item>
    <item>
      <title>Re: Analyzing Data Using Long form dataset (multiple observations for each participant)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Analyzing-Data-Using-Long-form-dataset-multiple-observations-for/m-p/779548#M248295</link>
      <description>&lt;PRE&gt;data have;
input StudyID     Visit   Marriage $ Age  ;
cards;
104                  1                        .                        8                                   .
104                  2                          Yes                             9                                    Yes
104                  3                           No                             .                          No
105                  1                           .                     .                          .
105                  2                           .                      .                          .
105                  3                          Yes                              10                                    Yes
106                  1                          .                        .                        .
106                  2                           Yes                             9                                      No
106                  3                           No                              10  
;

data first_Marriage;
 set have(where=(Marriage is not missing));
 by StudyID;
if first.StudyID;
keep StudyID Visit Marriage;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Nov 2021 12:35:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Analyzing-Data-Using-Long-form-dataset-multiple-observations-for/m-p/779548#M248295</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-11-10T12:35:03Z</dc:date>
    </item>
  </channel>
</rss>

