<?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: Creating a Variable from multiple variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-Variable-from-multiple-variables/m-p/352543#M82198</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ad44;
set ad45;
time = max(of MosLater1-MosLater14);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 23 Apr 2017 02:27:49 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2017-04-23T02:27:49Z</dc:date>
    <item>
      <title>Creating a Variable from multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-Variable-from-multiple-variables/m-p/352540#M82195</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to get the following code to work where I basically want to create the variable "time" from the largest "MosLater" variable for each participant, but the code that I'm using is just producing all blanks for some reason when creating the time variable (no errors in the log though)... Any ideas on how to get this to work?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data ad44;&lt;BR /&gt;set ad45;&lt;BR /&gt;if MosLater14=. then time=MosLater13;&lt;BR /&gt;else if MosLater13=. then time=MosLater12;&lt;BR /&gt;else if MosLater12=. then time=MosLater11;&lt;BR /&gt;else if MosLater11=. then time=MosLater10;&lt;BR /&gt;else if MosLater10=. then time=MosLater9;&lt;BR /&gt;else if MosLater9=. then time=MosLater8;&lt;BR /&gt;else if MosLater8=. then time=MosLater7;&lt;BR /&gt;else if MosLater7=. then time=MosLater6;&lt;BR /&gt;else if MosLater6=. then time=MosLater5;&lt;BR /&gt;else if MosLater5=. then time=MosLater4;&lt;BR /&gt;else if MosLater4=. then time=MosLater3;&lt;BR /&gt;else if MosLater3=. then time=MosLater2;&lt;BR /&gt;else if MosLater2=. then time=MosLater1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cody&lt;/P&gt;</description>
      <pubDate>Sun, 23 Apr 2017 02:14:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-Variable-from-multiple-variables/m-p/352540#M82195</guid>
      <dc:creator>chavens</dc:creator>
      <dc:date>2017-04-23T02:14:52Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a Variable from multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-Variable-from-multiple-variables/m-p/352541#M82196</link>
      <description>&lt;P&gt;In a different datastep, I already created the variable time via the code:&amp;nbsp;&lt;SPAN&gt;time=MosLater14;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Apr 2017 02:19:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-Variable-from-multiple-variables/m-p/352541#M82196</guid>
      <dc:creator>chavens</dc:creator>
      <dc:date>2017-04-23T02:19:44Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a Variable from multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-Variable-from-multiple-variables/m-p/352543#M82198</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ad44;
set ad45;
time = max(of MosLater1-MosLater14);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 23 Apr 2017 02:27:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-Variable-from-multiple-variables/m-p/352543#M82198</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-04-23T02:27:49Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a Variable from multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-Variable-from-multiple-variables/m-p/352546#M82200</link>
      <description>&lt;P&gt;Coalesce()?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: by largest do you mean the largest value across or the largest MOS variable? It appears the latter according to your code but the former according to your question.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Apr 2017 02:33:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-Variable-from-multiple-variables/m-p/352546#M82200</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-23T02:33:39Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a Variable from multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-Variable-from-multiple-variables/m-p/352547#M82201</link>
      <description>&lt;P&gt;Given your narrative and especially your code it looks to mee that you don't want to pick the largest value from the MosLater variables (that's what &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;code does)&amp;nbsp;but you want to pick the first non-missing value from a variable list ordered descending&amp;nbsp;from 14 to 1 (MosLater14 - MosLater1). That's what below code does.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  array MosLater {14};
  do _i=1 to dim(MosLater);
    MosLater[_i]=ceil(ranuni(1)*100);
    output;
  end;
  drop _i;
  stop;
run;

data want;
  length time 8.;
  set have;
  time = coalesce(of MosLater14-MosLater1);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Change history:&lt;/P&gt;
&lt;P&gt;Code amended based on&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;'s comment (removal of array statement).&lt;/P&gt;</description>
      <pubDate>Sun, 23 Apr 2017 03:09:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-Variable-from-multiple-variables/m-p/352547#M82201</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-04-23T03:09:55Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a Variable from multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-Variable-from-multiple-variables/m-p/352553#M82202</link>
      <description>I did mean to pick the biggest of the MosLater variable. If MosLater5 was the first missing then 6-14 would also be missing (and also 3&amp;lt;4&amp;lt;5&amp;lt;6...etc). I just could not think of how to do that initially, thus the confusing and inefficient code.&lt;BR /&gt;&lt;BR /&gt;Thanks!</description>
      <pubDate>Sun, 23 Apr 2017 02:45:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-Variable-from-multiple-variables/m-p/352553#M82202</guid>
      <dc:creator>chavens</dc:creator>
      <dc:date>2017-04-23T02:45:41Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a Variable from multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-Variable-from-multiple-variables/m-p/352555#M82204</link>
      <description>&lt;P&gt;Using Patricks code, but you can skip the array declaration, unless you're using it elsewhere.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;time2 = coalesce(of MosLater14-MosLater1);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 23 Apr 2017 02:50:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-Variable-from-multiple-variables/m-p/352555#M82204</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-23T02:50:12Z</dc:date>
    </item>
  </channel>
</rss>

