<?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: arrays with first. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11665#M1133</link>
    <description>1) GENERALITY OF CODE:  If in your experience groups of BY variables are often of mixed types (numeric and character), then what I’m saying is true: my code is more general than Chung’s rewrite of your code, since his does not allow the by-variables to be of mixed (numeric and character) types (because he uses an ARRAY statement).  Not “perhaps,” just a simple SAS fact.&lt;BR /&gt;
&lt;BR /&gt;
2) UNDERSTANDING:  I understood exactly what you’re saying: yes, of course, as a general rule groups of BY variables of different types (numeric and character) can be used on BY or CLASS statements.  Since my code handles that, clearly I did not think it was terribly uncommon, nor did I think it was a problem generally.&lt;BR /&gt;
&lt;BR /&gt;
However, there are cases where it can be a problem, so without pulling any muscles, I try to remain cognizant of that generally and generally try to avoid mixing.  For example, I often use a macro variable to contain the names of a group of BY variable names (as I did in my macro – very common).  But if I wanted to perform some repetitive operation on them in a data step, an ARRAY would be a likely choice, but I could not do so in an ARRAY statement if they are of mixed TYPEs.  &lt;BR /&gt;
&lt;BR /&gt;
That’s just one example, so if a string of variable names are being used in macro variable, mixing the types CAN be a problem.  So to the extent that it can trip up the unsuspecting code, it IS relevant.&lt;BR /&gt;
&lt;BR /&gt;
3) FORCING A SOLUTION TO USE ARRAYS:  I think you are taking polingjw’s request way too literally.  Polingjw is the only person who can confirm or deny this, but it was clear to me that s/he was more familiar with arrays and so wrote the “conceptual code” using arrays only to make the point (hence the disclaimer) that s/he wanted to process by-variables succinctly, but did not necessarily need the solution literally to use arrays.  Rather, “Does anyone have any alternatives to make this code work?” to me means solve the problem of executing some code whenever hitting a first.var value.  I whether or not a solution uses arrays is irrelevant.</description>
    <pubDate>Thu, 17 Feb 2011 00:15:07 GMT</pubDate>
    <dc:creator>jdopdyke</dc:creator>
    <dc:date>2011-02-17T00:15:07Z</dc:date>
    <item>
      <title>arrays with first.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11645#M1113</link>
      <description>Is there any way to use array variable references in conjunction with first.variable processing?  I want to write a datastep that is somewhat analogous to the following:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data new;&lt;BR /&gt;
	set old;&lt;BR /&gt;
	by variables:;&lt;BR /&gt;
	array variables{*} variables:;&lt;BR /&gt;
	do i=1 to dim(variables);&lt;BR /&gt;
		if first.variables{i} then do;&lt;BR /&gt;
			&lt;SOME additional="" code=""&gt;&lt;BR /&gt;
		end;&lt;BR /&gt;
	end;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
[pre]&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Of course, this code will produce an error due to the syntax of “first.variables{i}.”  Does anyone have any alternatives to make this code work?&lt;/SOME&gt;</description>
      <pubDate>Wed, 16 Feb 2011 16:46:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11645#M1113</guid>
      <dc:creator>polingjw</dc:creator>
      <dc:date>2011-02-16T16:46:13Z</dc:date>
    </item>
    <item>
      <title>Re: arrays with first.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11646#M1114</link>
      <description>Consider using SAS macro code with your BY variable list explicitly referenced as a %LET string, parse the list with %SCAN(...), to generate the specific DATA step DO/END code piece using %DO/%END logic.  &lt;BR /&gt;
&lt;BR /&gt;
As mentioned, you cannot reference an array variable when using FIRST.&lt;VARNAME&gt; so you will need to generate the SAS code with explicit BY variables, each mentioned individually as &lt;VARNAME&gt; above.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;/VARNAME&gt;&lt;/VARNAME&gt;</description>
      <pubDate>Wed, 16 Feb 2011 17:11:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11646#M1114</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2011-02-16T17:11:55Z</dc:date>
    </item>
    <item>
      <title>Re: arrays with first.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11647#M1115</link>
      <description>* J.D. Opdyke, President, DataMineIt;&lt;BR /&gt;
* Below is an actual solution to your question;&lt;BR /&gt;
&lt;BR /&gt;
options label symbolgen fullstimer yearcutoff=1950 nocenter ls = 256 ps = 51 msymtabmax=max mprint mlogic minoperator mindelimiter=' ' cleanup;&lt;BR /&gt;
&lt;BR /&gt;
data old(sortedby=a b c);&lt;BR /&gt;
  do a=1 to 2;&lt;BR /&gt;
    do b=11 to 12;&lt;BR /&gt;
	   do c = 21 to 22;&lt;BR /&gt;
		  do d = 100 to 104;&lt;BR /&gt;
		    output;&lt;BR /&gt;
		  end;&lt;BR /&gt;
		end;&lt;BR /&gt;
	 end;&lt;BR /&gt;
  end;&lt;BR /&gt;
  run;&lt;BR /&gt;
proc print data=old;&lt;BR /&gt;
  run;&lt;BR /&gt;
&lt;BR /&gt;
*** The code below assumes that what you want to do is simply "output" &lt;BR /&gt;
    The output statement is just a placehold for whatever code you&lt;BR /&gt;
    want to put there.&lt;BR /&gt;
&lt;BR /&gt;
*** If you need to extract all the byvars from the old dataset,&lt;BR /&gt;
    just use a proc contents and a proc sql&lt;BR /&gt;
***;&lt;BR /&gt;
&lt;BR /&gt;
%macro firstdotbyvars(indata=, outdata=, byvars=);&lt;BR /&gt;
&lt;BR /&gt;
%let num_byvars = %sysfunc(countw(&amp;amp;byvars.));&lt;BR /&gt;
%do i=1 %to &amp;amp;num_byvars.;&lt;BR /&gt;
  %let byvar&amp;amp;i. = %scan(&amp;amp;byvars.,&amp;amp;i.);&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
%macro iffirst;&lt;BR /&gt;
  if first.&amp;amp;byvar1. then do;&lt;BR /&gt;
     output;&lt;BR /&gt;
  end;&lt;BR /&gt;
  %if &amp;amp;num_byvars.&amp;gt;1 %then %do;&lt;BR /&gt;
     %do i=2 %to &amp;amp;num_byvars.;&lt;BR /&gt;
        else if first.&amp;amp;&amp;amp;byvar&amp;amp;i. then do;&lt;BR /&gt;
          output;&lt;BR /&gt;
        end;&lt;BR /&gt;
     %end;&lt;BR /&gt;
  %end;&lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
data new;&lt;BR /&gt;
  set old;&lt;BR /&gt;
  by &amp;amp;byvars.;&lt;BR /&gt;
  %iffirst&lt;BR /&gt;
  run;&lt;BR /&gt;
&lt;BR /&gt;
proc print data=new;&lt;BR /&gt;
  run;&lt;BR /&gt;
%mend firstdotbyvars;&lt;BR /&gt;
&lt;BR /&gt;
%firstdotbyvars(indata=old, outdata=new, byvars=a b c);</description>
      <pubDate>Wed, 16 Feb 2011 17:18:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11647#M1115</guid>
      <dc:creator>jdopdyke</dc:creator>
      <dc:date>2011-02-16T17:18:11Z</dc:date>
    </item>
    <item>
      <title>Re: arrays with first.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11648#M1116</link>
      <description>Thanks Scott.  I had thought about writing a macro to accomplish this task, but I was hoping that there would be an easier alternative.  I appreciate your advice.</description>
      <pubDate>Wed, 16 Feb 2011 17:19:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11648#M1116</guid>
      <dc:creator>polingjw</dc:creator>
      <dc:date>2011-02-16T17:19:21Z</dc:date>
    </item>
    <item>
      <title>Re: arrays with first.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11649#M1117</link>
      <description>FYI - Using a proc contents, outputting a dataset, and using a proc sql to get all the variables into a macro string will get around Scott's need to explicitly type out all the by-variable names.</description>
      <pubDate>Wed, 16 Feb 2011 17:21:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11649#M1117</guid>
      <dc:creator>jdopdyke</dc:creator>
      <dc:date>2011-02-16T17:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: arrays with first.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11650#M1118</link>
      <description>Thanks for posting this solution.  I appreciate the help.</description>
      <pubDate>Wed, 16 Feb 2011 17:22:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11650#M1118</guid>
      <dc:creator>polingjw</dc:creator>
      <dc:date>2011-02-16T17:22:21Z</dc:date>
    </item>
    <item>
      <title>Re: arrays with first.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11651#M1119</link>
      <description>I doubt the OP is going to want to use CONTENTS with all variables from a given SAS file in a BY list - more likely a subset list and that's why I would consider the %LET definition (explicitly) to be more appropriate.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 16 Feb 2011 17:42:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11651#M1119</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2011-02-16T17:42:12Z</dc:date>
    </item>
    <item>
      <title>Re: arrays with first.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11652#M1120</link>
      <description>My actual solution allows the user to do it either way.&lt;BR /&gt;
&lt;BR /&gt;
The macro allows the user to type them out Scott.&lt;BR /&gt;
&lt;BR /&gt;
OR if serious automation is required, then if the user has thought ahead and named the key byvariables similarly, say, with a common prefix, then it is a trivial matter to drop those outputted by the proc contents that don’t matter Scott.&lt;BR /&gt;
&lt;BR /&gt;
And then it is fully automated, which is typically much more appropriate, unless the task is a small one-off little piece of code that can be banged out in 6 minutes.&lt;BR /&gt;
&lt;BR /&gt;
J.D. Opdyke, President, DataMineIt</description>
      <pubDate>Wed, 16 Feb 2011 17:52:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11652#M1120</guid>
      <dc:creator>jdopdyke</dc:creator>
      <dc:date>2011-02-16T17:52:07Z</dc:date>
    </item>
    <item>
      <title>Re: arrays with first.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11653#M1121</link>
      <description>You can't use the exact syntax you suggest because you can't create an array of mixed data types, or reference FIRST.array[index] as you have already determined.  You CAN however create an array of FIRST or LAST variables.  &lt;BR /&gt;
&lt;BR /&gt;
The example doesn't really do any thing by illustrate the syntax.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc plan ordered;&lt;BR /&gt;
   factors a=3 first=2 c=3 i=4 / noprint;&lt;BR /&gt;
   output out=test first cvals=('a' 'b');&lt;BR /&gt;
   run;&lt;BR /&gt;
   quit;&lt;BR /&gt;
&lt;BR /&gt;
options validvarname=any;&lt;BR /&gt;
data test2;&lt;BR /&gt;
   set test;&lt;BR /&gt;
   by a first c;&lt;BR /&gt;
   array f&lt;LI&gt; 'first.'n:;&lt;BR /&gt;
   put 'NOTE: ' _n_= @;&lt;BR /&gt;
   do j = 1 to dim(f);&lt;BR /&gt;
      if f&lt;J&gt; then put f&lt;J&gt;= @;&lt;BR /&gt;
      end;&lt;BR /&gt;
   put;&lt;BR /&gt;
   run;&lt;BR /&gt;
options validvarname=v7;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Fixed OUTPUT statement in PROC PLAN.&lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: data _null_;&lt;/J&gt;&lt;/J&gt;&lt;/LI&gt;</description>
      <pubDate>Wed, 16 Feb 2011 19:35:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11653#M1121</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2011-02-16T19:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: arrays with first.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11654#M1122</link>
      <description>In fairness, polingjw did state, “Of course, this code will produce an error due to the syntax of “first.variables{i}.” ”&lt;BR /&gt;
&lt;BR /&gt;
J.D.’s code above works, as does data _null_’s (although purists (I’d say prudes) might complain about the WARNING: note in data _null_’s SAS .log).</description>
      <pubDate>Wed, 16 Feb 2011 20:04:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11654#M1122</guid>
      <dc:creator>jdopdyke</dc:creator>
      <dc:date>2011-02-16T20:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: arrays with first.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11655#M1123</link>
      <description>&amp;gt; In fairness, polingjw did state, “Of course, this&lt;BR /&gt;
&amp;gt; code will produce an error due to the syntax of&lt;BR /&gt;
&amp;gt; “first.variables{i}.” ”&lt;BR /&gt;
I did go on to say "as you have determined".&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; J.D.’s code above works, as does data _null_’s&lt;BR /&gt;
&amp;gt; (although purists (I’d say prudes) might complain&lt;BR /&gt;
&amp;gt; about the WARNING: note in data _null_’s SAS .log).&lt;BR /&gt;
&lt;BR /&gt;
Thanks for pointing out the WARNING.  I had changed the variable B to FIRST but forgot to change the OUTPUT statement where I defined CVALS.  No warning now.</description>
      <pubDate>Wed, 16 Feb 2011 20:27:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11655#M1123</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2011-02-16T20:27:48Z</dc:date>
    </item>
    <item>
      <title>Re: arrays with first.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11656#M1124</link>
      <description>data _null_,&lt;BR /&gt;
&lt;BR /&gt;
Wow!  I thought that the validvarname option was only for compatibility with DBMS variable names.  This is exactly what I was hoping to find!</description>
      <pubDate>Wed, 16 Feb 2011 20:29:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11656#M1124</guid>
      <dc:creator>polingjw</dc:creator>
      <dc:date>2011-02-16T20:29:19Z</dc:date>
    </item>
    <item>
      <title>Re: arrays with first.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11657#M1125</link>
      <description>I think you misunderstood. You can use the output data set of PROC CONTENTS to get the by variables. The sortedby variable contains the numerical order of the by variables, if any. So you can programatically build the list of by variables in the correct order for any dataset without any prior knowledge of it. Quick example that anyone can run:&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=sashelp.cars out=cars;&lt;BR /&gt;
by origin make drivetrain;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc contents noprint data=cars out=cars_contents;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
select name&lt;BR /&gt;
   into :byvars separated by ' '&lt;BR /&gt;
from cars_contents&lt;BR /&gt;
where sortedby is not null&lt;BR /&gt;
order by sortedby&lt;BR /&gt;
;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
%put byvars=&amp;amp;byvars;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; I doubt the OP is going to want to use CONTENTS with&lt;BR /&gt;
&amp;gt; all variables from a given SAS file in a BY list -&lt;BR /&gt;
&amp;gt; more likely a subset list and that's why I would&lt;BR /&gt;
&amp;gt; consider the %LET definition (explicitly) to be more&lt;BR /&gt;
&amp;gt; appropriate.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Scott Barry&lt;BR /&gt;
&amp;gt; SBBWorks, Inc.</description>
      <pubDate>Wed, 16 Feb 2011 20:31:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11657#M1125</guid>
      <dc:creator>FloydNevseta</dc:creator>
      <dc:date>2011-02-16T20:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: arrays with first.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11658#M1126</link>
      <description>Without validvarname=any you can still create an array of first.var&lt;BR /&gt;
&lt;BR /&gt;
array f&lt;LI&gt; first:;&lt;BR /&gt;
&lt;BR /&gt;
But there is more possibility of problems from user variables that begin with FIRST.  I "never" use validvarname=any except for very special situations so the technique should be mostly safe.&lt;/LI&gt;</description>
      <pubDate>Wed, 16 Feb 2011 20:36:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11658#M1126</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2011-02-16T20:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: arrays with first.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11659#M1127</link>
      <description>I think data _null_'s solution naturally leads to a simpler solution below. It makes a number of assumptions, of course, but may work out when you have a reasonable idea about what the variable names are in the input dataset.&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;/*&amp;nbsp;test&amp;nbsp;data&amp;nbsp;*/&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#000080;font-family:Courier New;font-size:10pt;"&gt;proc&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#000080;font-family:Courier New;font-size:10pt;"&gt;plan&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;ordered&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;factors&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;var1=&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#008080;font-family:Courier New;font-size:10pt;"&gt;2&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;var2=&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#008080;font-family:Courier New;font-size:10pt;"&gt;2&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;var3=&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#008080;font-family:Courier New;font-size:10pt;"&gt;3&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;/&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;noprint&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;output&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;out&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;=old;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#000080;font-family:Courier New;font-size:10pt;"&gt;run&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#000080;font-family:Courier New;font-size:10pt;"&gt;quit&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&amp;nbsp;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;/*&amp;nbsp;do&amp;nbsp;something&amp;nbsp;when&amp;nbsp;we&amp;nbsp;hit&amp;nbsp;any&amp;nbsp;first.var&amp;nbsp;*/&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#000080;font-family:Courier New;font-size:10pt;"&gt;data&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;new;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;old;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;by&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;var:;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;array&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;firsts(*)&amp;nbsp;first:;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&amp;nbsp;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;drop&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;i;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;do&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;i&amp;nbsp;=&amp;nbsp;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#008080;font-family:Courier New;font-size:10pt;"&gt;1&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;to&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;dim(firsts);&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;put&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;firsts(i)&amp;nbsp;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#008080;font-family:Courier New;font-size:10pt;"&gt;2.&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;@;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#0000FF;font-family:Courier New;font-size:10pt;"&gt;put&lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="color:#000080;font-family:Courier New;font-size:10pt;"&gt;run&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;/*&amp;nbsp;on&amp;nbsp;log&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&amp;nbsp;1&amp;nbsp;1&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;0&amp;nbsp;0&amp;nbsp;1&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;0&amp;nbsp;0&amp;nbsp;1&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;0&amp;nbsp;1&amp;nbsp;1&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;0&amp;nbsp;0&amp;nbsp;1&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;0&amp;nbsp;0&amp;nbsp;1&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&amp;nbsp;1&amp;nbsp;1&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;0&amp;nbsp;0&amp;nbsp;1&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;0&amp;nbsp;0&amp;nbsp;1&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;0&amp;nbsp;1&amp;nbsp;1&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;0&amp;nbsp;0&amp;nbsp;1&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;0&amp;nbsp;0&amp;nbsp;1&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P style="padding:0"&gt;&lt;SPAN style="color:#008000;font-family:Courier New;font-size:10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;*/&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
p.s. Well, ... did not know that data _null_ has already posted a follow up with exactly the same idea moments earlier... &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;BR /&gt;  &lt;BR /&gt;
Message was edited by: chang_y_chung@hotmail.com</description>
      <pubDate>Wed, 16 Feb 2011 21:05:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11659#M1127</guid>
      <dc:creator>chang_y_chung_hotmail_com</dc:creator>
      <dc:date>2011-02-16T21:05:23Z</dc:date>
    </item>
    <item>
      <title>Re: arrays with first.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11660#M1128</link>
      <description>I had written it your way first, as that was what I remembered from our conversations on SAS-L on this subject.  The problem with the simplier approach is user define variables that begin with FIRST  using 'FIRST.'n is a bit safer.</description>
      <pubDate>Wed, 16 Feb 2011 21:14:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11660#M1128</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2011-02-16T21:14:58Z</dc:date>
    </item>
    <item>
      <title>Re: arrays with first.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11661#M1129</link>
      <description>Agreed – data _null_’s is a nice solution.&lt;BR /&gt;
&lt;BR /&gt;
But J.D.’s is more general.  For example, it can mix variable types amongst the by-variables, which is not a terribly infrequent occurrence.</description>
      <pubDate>Wed, 16 Feb 2011 21:26:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11661#M1129</guid>
      <dc:creator>jdopdyke</dc:creator>
      <dc:date>2011-02-16T21:26:20Z</dc:date>
    </item>
    <item>
      <title>Re: arrays with first.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11662#M1130</link>
      <description>&amp;gt; But J.D.’s is more general.  For example, it can mix&lt;BR /&gt;
&amp;gt; variable types amongst the by-variables, which is not&lt;BR /&gt;
&amp;gt; a terribly infrequent occurrence.&lt;BR /&gt;
&lt;BR /&gt;
I would say BY variables lists of mixed data types is the norm.  The BY variable TYPE is not an issue.  The ARRAY is of FIRSTdot variables which are always numeric.  My corrected example illustrates this as the variable FIRST is defined as a character variable.</description>
      <pubDate>Wed, 16 Feb 2011 21:48:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11662#M1130</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2011-02-16T21:48:35Z</dc:date>
    </item>
    <item>
      <title>Re: arrays with first.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11663#M1131</link>
      <description>Actually, in your (data _null_'s) first posting, “first” is a numeric variable (because you hadn’t swapped b for “first”).&lt;BR /&gt;
&lt;BR /&gt;
But in your second posting, you are correct – apologies.  My comment is only true of Chung’s rewrite of your code, and mine is more general than Chung’s rewrite.&lt;BR /&gt;
&lt;BR /&gt;
As an aside, when possible I try not to mix types, so I’ve seen it more frequently when I’m forced to inherit others’ code.</description>
      <pubDate>Wed, 16 Feb 2011 22:01:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11663#M1131</guid>
      <dc:creator>jdopdyke</dc:creator>
      <dc:date>2011-02-16T22:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: arrays with first.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11664#M1132</link>
      <description>&amp;gt; Actually, in your (data _null_'s) first posting,&lt;BR /&gt;
&amp;gt; “first” is a numeric variable (because you hadn’t&lt;BR /&gt;
&amp;gt; swapped b for “first”).&lt;BR /&gt;
Yes, that's what I said.  But it is still irrelevant.  The data type of the BY variable is not the issue.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; But in your second posting, you are correct –&lt;BR /&gt;
&amp;gt; apologies.  My comment is only true of Chung’s&lt;BR /&gt;
&amp;gt; rewrite of your code, and mine is more general than&lt;BR /&gt;
&amp;gt; Chung’s rewrite.&lt;BR /&gt;
Perhaps, but you have not defined an array of first variables.  If would rather have seen a macro to write an ARRAY statement, that's what the OP was looking for.&lt;BR /&gt;
&lt;BR /&gt;
[pre]array f&lt;LI&gt; first.a first.b first.c;[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; As an aside, when possible I try not to mix types, so&lt;BR /&gt;
&amp;gt; I’ve seen it more frequently when I’m forced to&lt;BR /&gt;
&amp;gt; inherit others’ code.&lt;BR /&gt;
You misunderstand me, I was saying it is normal to have BY variables that have different data types.  As in my example. A is numeric, First is character, C is numeric.  Very common and not a problem.&lt;/LI&gt;</description>
      <pubDate>Wed, 16 Feb 2011 22:57:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-with-first/m-p/11664#M1132</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2011-02-16T22:57:03Z</dc:date>
    </item>
  </channel>
</rss>

