<?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 user ask for help: How build a new variable by select one from four variables? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/New-user-ask-for-help-How-build-a-new-variable-by-select-one/m-p/897954#M39941</link>
    <description>&lt;P&gt;Considering you might want to solve this in SAS, the following will work. You want to use an array to iterate through the available measures (var1-var4). You will assign &lt;EM&gt;first&lt;/EM&gt; to be the first non-missing value and assign &lt;EM&gt;last&lt;/EM&gt; to be the last non-missing value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    array visits [*] var1-var4;
    do i = 1 to dim(visits);
        if first=. then first=visits[i];       
        if visits[i]^=. then last=visits[i];
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 10 Oct 2023 13:24:17 GMT</pubDate>
    <dc:creator>antonbcristina</dc:creator>
    <dc:date>2023-10-10T13:24:17Z</dc:date>
    <item>
      <title>New user ask for help: How build a new variable by select one from four variables?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/New-user-ask-for-help-How-build-a-new-variable-by-select-one/m-p/897891#M39937</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am a new user ask for help. Attached the sample data, I have four variables from 4 visits which acutually measured the same biological marker. Subjects were measured in one or two visits but not all, so the Var 1-4 had missing values. I want to build a new variable, by selecting one from the four variables. &lt;/P&gt;
&lt;P&gt;1. How to select from the first available data in the four visits to build the new one?&lt;/P&gt;
&lt;P&gt;2. How to select the last available data in the four visits to build the new one?&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;Jing&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2023-10-10 102037.png" style="width: 876px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88732i7DFFC5C074D7BCB9/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2023-10-10 102037.png" alt="Screenshot 2023-10-10 102037.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 02:22:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/New-user-ask-for-help-How-build-a-new-variable-by-select-one/m-p/897891#M39937</guid>
      <dc:creator>jing2000yr</dc:creator>
      <dc:date>2023-10-10T02:22:02Z</dc:date>
    </item>
    <item>
      <title>Re: New user ask for help: How build a new variable by select one from four variables?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/New-user-ask-for-help-How-build-a-new-variable-by-select-one/m-p/897895#M39938</link>
      <description>&lt;P&gt;You seem to have an Excel issue. You posted a screenshot of an Excel spreadsheet, and attached an Excel file.&lt;/P&gt;
&lt;P&gt;I recommend that you post your question at an Excel-oriented forum, this here are the&amp;nbsp;&lt;STRONG&gt;SAS&lt;/STRONG&gt; communities.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 04:04:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/New-user-ask-for-help-How-build-a-new-variable-by-select-one/m-p/897895#M39938</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-10-10T04:04:34Z</dc:date>
    </item>
    <item>
      <title>Re: New user ask for help: How build a new variable by select one from four variables?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/New-user-ask-for-help-How-build-a-new-variable-by-select-one/m-p/897954#M39941</link>
      <description>&lt;P&gt;Considering you might want to solve this in SAS, the following will work. You want to use an array to iterate through the available measures (var1-var4). You will assign &lt;EM&gt;first&lt;/EM&gt; to be the first non-missing value and assign &lt;EM&gt;last&lt;/EM&gt; to be the last non-missing value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    array visits [*] var1-var4;
    do i = 1 to dim(visits);
        if first=. then first=visits[i];       
        if visits[i]^=. then last=visits[i];
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 13:24:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/New-user-ask-for-help-How-build-a-new-variable-by-select-one/m-p/897954#M39941</guid>
      <dc:creator>antonbcristina</dc:creator>
      <dc:date>2023-10-10T13:24:17Z</dc:date>
    </item>
    <item>
      <title>Re: New user ask for help: How build a new variable by select one from four variables?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/New-user-ask-for-help-How-build-a-new-variable-by-select-one/m-p/897957#M39942</link>
      <description>&lt;P&gt;Use the COALESCE() function to select the first non-missing value from a list.&amp;nbsp; Since your variable names have numeric suffixes you can use a variable list.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;first = coalesce(of var1-var4);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Otherwise just list the variable names:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;first = coalesce(of varA varB varC varD);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To find the last non-missing value just list the variables in the opposite order.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;last = coalesce(of var4-var1);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Oct 2023 13:34:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/New-user-ask-for-help-How-build-a-new-variable-by-select-one/m-p/897957#M39942</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-10-10T13:34:34Z</dc:date>
    </item>
  </channel>
</rss>

