<?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: How to create baseline_data in a easy way in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-baseline-data-in-a-easy-way/m-p/858664#M339262</link>
    <description>&lt;P&gt;Define "easy".&lt;/P&gt;
&lt;P&gt;I can do it in slightly shorter code but whether it is easier or not is questionable.&lt;/P&gt;
&lt;P&gt;Untested code as no values provided&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;array ab (*) R9AGEY_B R10AGEY_B R11AGEY_B R12AGEY_B R13AGEY_B R14AGEY_B;
baseline = ab [whichn(1,lle9^=. ,lle10^=.,lle11^=.,lle12^=.,lle13^=.,lle14^=.)];
&lt;/PRE&gt;
&lt;P&gt;The Whichn, and character version Whichc, returns the position of the first expression or value following the first that matches that value. So we find the first result of 1 from the comparisons. SAS will return 1 for true so evaluating lle9 ^=. results in 1 when not missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The ARRAY allows addressing a value of the array using it's position number. This is where the bit about middle of the variable comes in. You will learn that with SAS it often a much better idea to name the variable R_agey_b9, or similar. Then the list could have been R_agey_b9 -R_agey_b14.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the above to work you have to make sure that the order of the comparisons matches that of the variables in the array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or a two array solution&lt;/P&gt;
&lt;PRE&gt;array ab (*) R9AGEY_B R10AGEY_B R11AGEY_B R12AGEY_B R13AGEY_B R14AGEY_B;
array l (*) lle9 - lle14;
do i=1 to dim(l);
   if l[i] ne . then do;
      baseline=ab[i];
      leave;
   end;
run;&lt;/PRE&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;</description>
    <pubDate>Tue, 14 Feb 2023 06:06:58 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-02-14T06:06:58Z</dc:date>
    <item>
      <title>How to create baseline_data in a easy way</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-baseline-data-in-a-easy-way/m-p/858643#M339249</link>
      <description>&lt;P&gt;Is there any easy to express the sentences below?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if lle9^=. then age_baseline=R9AGEY_B;&lt;BR /&gt;else if lle10^=. then age_baseline=R10AGEY_B;&lt;BR /&gt;else if lle11^=. then age_baseline=R11AGEY_B;&lt;BR /&gt;else if lle12^=. then age_baseline=R12AGEY_B;&lt;BR /&gt;else if lle13^=. then age_baseline=R13AGEY_B;&lt;BR /&gt;else if lle14^=. then age_baseline=R14AGEY_B;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 00:14:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-baseline-data-in-a-easy-way/m-p/858643#M339249</guid>
      <dc:creator>nwang5</dc:creator>
      <dc:date>2023-02-14T00:14:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to create baseline_data in a easy way</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-baseline-data-in-a-easy-way/m-p/858664#M339262</link>
      <description>&lt;P&gt;Define "easy".&lt;/P&gt;
&lt;P&gt;I can do it in slightly shorter code but whether it is easier or not is questionable.&lt;/P&gt;
&lt;P&gt;Untested code as no values provided&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;array ab (*) R9AGEY_B R10AGEY_B R11AGEY_B R12AGEY_B R13AGEY_B R14AGEY_B;
baseline = ab [whichn(1,lle9^=. ,lle10^=.,lle11^=.,lle12^=.,lle13^=.,lle14^=.)];
&lt;/PRE&gt;
&lt;P&gt;The Whichn, and character version Whichc, returns the position of the first expression or value following the first that matches that value. So we find the first result of 1 from the comparisons. SAS will return 1 for true so evaluating lle9 ^=. results in 1 when not missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The ARRAY allows addressing a value of the array using it's position number. This is where the bit about middle of the variable comes in. You will learn that with SAS it often a much better idea to name the variable R_agey_b9, or similar. Then the list could have been R_agey_b9 -R_agey_b14.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the above to work you have to make sure that the order of the comparisons matches that of the variables in the array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or a two array solution&lt;/P&gt;
&lt;PRE&gt;array ab (*) R9AGEY_B R10AGEY_B R11AGEY_B R12AGEY_B R13AGEY_B R14AGEY_B;
array l (*) lle9 - lle14;
do i=1 to dim(l);
   if l[i] ne . then do;
      baseline=ab[i];
      leave;
   end;
run;&lt;/PRE&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;</description>
      <pubDate>Tue, 14 Feb 2023 06:06:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-baseline-data-in-a-easy-way/m-p/858664#M339262</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-02-14T06:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to create baseline_data in a easy way</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-baseline-data-in-a-easy-way/m-p/858670#M339263</link>
      <description>&lt;P&gt;This "solution" demonstrates how to avoid loops:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options missing = '#';

data want;
   set have;

   length value $ 10 all $ 200 p baseline 8;

   array one lle9-lle14;
   array two R9AGEY_B R10AGEY_B R11AGEY_B R12AGEY_B R13AGEY_B R14AGEY_B;

   value = put(coalesce(of one[*]), best.);
   all = catx(' ', of one[*]);
   p = findw(all, strip(value), ' ', 'e');

   baseline = two[p];

   *drop value all p;
run;

options missing = '.';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;While coalesce still sees "missing", catx keeps missing values and displays them as #, so findw returns the number of the "word" matching the first non-missing value, which is the value of array two becoming the value of baseline.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In real-life i would use the second suggestion posted by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 06:43:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-baseline-data-in-a-easy-way/m-p/858670#M339263</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2023-02-14T06:43:14Z</dc:date>
    </item>
  </channel>
</rss>

