<?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: Array First.id retain last.id in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415719#M102002</link>
    <description>&lt;P&gt;Now that you have made some progress perhaps you can explain in more detail the overall picture.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looking at your final program and the 15 sample records you posted it looks like you really only have TWO variables in your source table. The SYMPTOM and SYMPTOM_NO fields have the same information.&amp;nbsp; When SYMPTOM_NO=1 then SYMPTOM is always equal to "Heartburns".&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
 infile cards truncover ;
 input id_no symptom_no symptom $20. ;
cards;
1 1 Heartburns
1 2 Sickness
4 5 Tiredness
6 1 Heartburns
7 4 Temperature
8 1 Heartburns
8 5 Tiredness
9 2 Sickness
9 3 Spasm
9 4 Temperature
10 3 Spasm
10 5 Tiredness
11 3 Spasm
11 5 Tiredness
12 4 Temperature
12 5 Tiredness
13 3 Spasm
13 4 Temperature
14 3 Spasm
15 1 Heartburns
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So what is it that you want to calculate in the data step?&amp;nbsp; Do you want to count how many times a given ID got a particular symptom? Perhaps you want to use the symptom names as the variable names in your array?&amp;nbsp; &amp;nbsp;Also what is this DISEASE variable you mentioned?&amp;nbsp; Is that something you are supposed to calculate?&amp;nbsp; Is it the count of how many records each ID had?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps you want something like this?&lt;/P&gt;
&lt;P&gt;This is an example of what is called a DOW loop.&amp;nbsp; It eliminates the need for retaining variables or an OUTPUT statement since it processes all of the records for a given BY group in the same iteration of the data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  do until (last.id_no);
    set have ;
    by id_no;
    array counts Heartburns Sickness Spasm Temperature Tiredness ;
    if first.id_no then do _n_=1 to dim(counts);
       counts(_n_)=0;
    end;
    counts(symptom_no)=counts(symptom_no)+1;
    disease=sum(disease,1);
  end;
  keep id_no Heartburns Sickness Spasm Temperature Tiredness Disease ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 520px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/16811iA97B1564E513FD8C/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 23 Nov 2017 00:32:25 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-11-23T00:32:25Z</dc:date>
    <item>
      <title>Array First.id retain last.id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415599#M101935</link>
      <description>&lt;P&gt;&lt;SPAN&gt;The Excel data file given to you has&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;18,082 observations with 3 variables&lt;/SPAN&gt;&lt;SPAN&gt;: ID_NO, SYMPTOM_NO, and SYMPTOM.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The first 20 observations of the excel file look like this&lt;/SPAN&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;id_no&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;symptom_no&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;symptom&lt;/P&gt;&lt;/TD&gt;&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lt;/STRONG&gt;instead of having multiple records per person, there should be one record per person and a variable for each possible symptom (see below): Following is the first 15 records of the newly organized data set.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Obs&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;id_no&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;sympt1&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;sympt2&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;sympt3&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;sympt4&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;sympt5&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;disease&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Heartburns&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Sickness&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;T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&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;15&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;19&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Sickness&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&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;&lt;P&gt;I cannot figure this out. This is the code I have....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro one (v1,v2); 
proc import out  = &amp;amp;v1
            datafile = "\\Client\C$\Users\jessica\Desktop\data\&amp;amp;v2"
            DBMS     = xlsx replace;
            getnames = YES;
run;


%mend one; 
%one (Project3, Project3_f17);

data new; 
	array new[7] id_no sympt1-sympt5;
	retain id_no sympt_no; 
	set Project3; 

by id; 

if first.id then do i=1 to 12549; 
	new[i]= .;
	end; 

	agency [disease] = disease; 
	if last.id then output; 
format sympt1-sympt5 disease.; 
keep id sympt1-sympt5; 
run; 
proc print data= new; 
 run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help!!!&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 18:43:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415599#M101935</guid>
      <dc:creator>jessica_join</dc:creator>
      <dc:date>2017-11-22T18:43:16Z</dc:date>
    </item>
    <item>
      <title>Re: Array First.id retain last.id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415604#M101939</link>
      <description>&lt;P&gt;You did not provide enough information for us to check what you are doing, but I did notice one thing.&amp;nbsp; Add these to your RETAIN statement.&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;sympt1&lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt;sympt5&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Your code would be easier to look at if you indented it nicely.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 18:56:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415604#M101939</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2017-11-22T18:56:35Z</dc:date>
    </item>
    <item>
      <title>Re: Array First.id retain last.id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415606#M101941</link>
      <description>&lt;P&gt;1. Using a macro to import is not very helpful in the long run, its just adding code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. You're really really close.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Here's a full walk through on how to do this:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/reshaping-data-long-to-wide-using-the-data-step/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/reshaping-data-long-to-wide-using-the-data-step/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're missing the assignment statement to assign the values based on the count.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new[symptom_no] = symptom;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And you're also missing the variables you're going to keep in the RETAIN statement, &lt;SPAN&gt;symptom1&lt;/SPAN&gt;-symptom5&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 18:58:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415606#M101941</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-22T18:58:42Z</dc:date>
    </item>
    <item>
      <title>Re: Array First.id retain last.id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415610#M101944</link>
      <description>&lt;P&gt;Why would you want to convert it?&amp;nbsp; If you do then use PROC TRANSPOSE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=want prefix=sympt ;
  by id_no;
  id symptom_no;
  var symptom ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is this a homework problem?&lt;/P&gt;
&lt;P&gt;If so&lt;/P&gt;
&lt;P&gt;Why did you include ID_NO in your ARRAY?&lt;/P&gt;
&lt;P&gt;Where did the variable ID and DISEASE come from?&lt;/P&gt;
&lt;P&gt;Do you know how to use the CALL MISSING() function?&lt;BR /&gt;Have you heard of DOW loops?&amp;nbsp; Google it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 19:04:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415610#M101944</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-11-22T19:04:06Z</dc:date>
    </item>
    <item>
      <title>Re: Array First.id retain last.id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415613#M101946</link>
      <description>It is not a homework problem. It is a study guide question. I thought I had to include ID_NO for it to show up in the overall solution. Disease is a variable he wants us to create. No I do not know how to use the Call Missing() function. Thank you.</description>
      <pubDate>Wed, 22 Nov 2017 19:09:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415613#M101946</guid>
      <dc:creator>jessica_join</dc:creator>
      <dc:date>2017-11-22T19:09:27Z</dc:date>
    </item>
    <item>
      <title>Re: Array First.id retain last.id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415615#M101947</link>
      <description>It appears indented to me. Perhaps it did not come through that way on your end?&lt;BR /&gt;Thank you!</description>
      <pubDate>Wed, 22 Nov 2017 19:10:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415615#M101947</guid>
      <dc:creator>jessica_join</dc:creator>
      <dc:date>2017-11-22T19:10:17Z</dc:date>
    </item>
    <item>
      <title>Re: Array First.id retain last.id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415628#M101952</link>
      <description>&lt;P&gt;Let's look at what you asked SAS to do.&lt;/P&gt;
&lt;P&gt;In the first three lines:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new; 
  array new[7] id_no sympt1-sympt5;
  retain id_no sympt_no; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You are making a dataset named NEW.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You defined a array named NEW with 7 elements, but you only listed 6 variables. That should cause an error. Note you don't need to include the [7] if you are listing the actual variable names. SAS can count how many variables you have listed and will define the array to have that many members.&lt;/P&gt;
&lt;P&gt;Since this is the first place these variables are mentioned they will all 6 be numeric variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You then marked two variables to be retained across loops. Since you have not mentioned&amp;nbsp;SYMPT_NO before so its type is still not known.&amp;nbsp; I suspect that you really want to retain are the SYMPT..... variables that you are going to use in your ARRAY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next you do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  set Project3; 
  by id; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So now you are bring in a dataset named PROJECT3.&amp;nbsp; So SAS will now know about the variables that are in that dataset. Notice that if any of the variables you have already defined as numeric are in that dataset as character variables you will get an error.&lt;/P&gt;
&lt;P&gt;You are assuming that it has a variable named ID and that it is sorted by that variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  if first.id then do i=1 to 12549; 
    new[i]= .;
  end; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now if the current observation is the first for this value of ID you are trying to set 12,549 members of the array NEW to missing. But you only defined the array to have 7 (or 6?) members. So that will generate a run time error when the loop counter I reaches 8.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  agency [disease] = disease; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you are referencing an array named AGENCY that you have not defined. That will cause an error when SAS tries to compile this data step.&amp;nbsp; The logic is wrong since you are just setting the value to the index number.&amp;nbsp; That is like saying X[1]=1, or X[2]=2.&amp;nbsp; Probably not what you want.&lt;/P&gt;
&lt;P&gt;You using the variable DISEASE, that you have not defined,&amp;nbsp; so a programmer reading this would assume came from the input dataset. SAS itself will know since it will have looked at the input dataset. So if DISEASE wasn't defined there then it will be created as numeric variable and have a missing value. If it was defined and it is a character variable then you will get another error because the index into an array reference has to be an integer.&amp;nbsp; If it is missing then (if it ever could run) it would cause an error at run time since missing value is not a valid index into an array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  if last.id then output; 
  format sympt1-sympt5 disease.; 
  keep id sympt1-sympt5; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You will only output one observation per value of the BY variable ID.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are attaching a format to the variables SYMT1-SYMPT5.&amp;nbsp; Syntactically this statement looks fine, but you have not defined the format DISEASE. anywhere in this code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And you are telling SAS that only 6 variables should be kept in the output dataset. So other variables like I, ID_NO, SYMPTOM_NO and DISEASE that your data step mentions will be dropped.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 19:45:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415628#M101952</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-11-22T19:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: Array First.id retain last.id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415643#M101959</link>
      <description>&lt;P&gt;Okay thank you for breaking it down.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just changed it to this...&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new; 
	set longsort; 
	by id_no; 
	Keep id_no sympt1 - sympt5; 
	retain sympt1 - sympt5; 
	array New_a (1:5) sympt1 - sympt5; 
	If first.id_no then
	do; 
	Do i = 1 to 5; 
		new_a (i) = .; 
		end; 
	end; 
	new_a (symptom_no) = symptom; 
	if last.symptom then output; 
		run; 
	proc print data= new; 
	run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The error code I am getting...&lt;/P&gt;&lt;P&gt;NOTE: Character values have been converted to numeric values at the places given by:&lt;BR /&gt;(Line):(Column).&lt;BR /&gt;202:5&lt;BR /&gt;NOTE: Variable last.symptom is uninitialized.&lt;BR /&gt;NOTE: Invalid numeric data, symptom='Heartburns' , at line 202 column 26.&lt;BR /&gt;id_no=1 symptom_no=1 symptom=Heartburns FIRST.id_no=1 LAST.id_no=0 sympt1=. sympt2=. sympt3=.&lt;BR /&gt;sympt4=. sympt5=. i=6 last.symptom=0 _ERROR_=1 _N_=1&lt;BR /&gt;NOTE: Invalid numeric data, symptom='Sickness' , at line 202 column 26.&lt;BR /&gt;id_no=1 symptom_no=2 symptom=Sickness FIRST.id_no=0 LAST.id_no=1 sympt1=. sympt2=. sympt3=.&lt;BR /&gt;sympt4=. sympt5=. i=. last.symptom=0 _ERROR_=1 _N_=2&lt;BR /&gt;NOTE: Invalid numeric data, symptom='Tiredness' , at line 202 column 26.&lt;BR /&gt;id_no=4 symptom_no=5 symptom=Tiredness FIRST.id_no=1 LAST.id_no=1 sympt1=. sympt2=. sympt3=.&lt;BR /&gt;sympt4=. sympt5=. i=6 last.symptom=0 _ERROR_=1 _N_=3&lt;BR /&gt;NOTE: Invalid numeric data, symptom='Heartburns' , at line 202 column 26.&lt;BR /&gt;id_no=6 symptom_no=1 symptom=Heartburns FIRST.id_no=1 LAST.id_no=1 sympt1=. sympt2=. sympt3=.&lt;BR /&gt;sympt4=. sympt5=. i=6 last.symptom=0 _ERROR_=1 _N_=4&lt;BR /&gt;NOTE: Invalid numeric data, symptom='Temperature' , at line 202 column 26.&lt;BR /&gt;id_no=7 symptom_no=4 symptom=Temperature FIRST.id_no=1 LAST.id_no=1 sympt1=. sympt2=. sympt3=.&lt;BR /&gt;sympt4=. sympt5=. i=6 last.symptom=0 _ERROR_=1 _N_=5&lt;BR /&gt;NOTE: Invalid numeric data, symptom='Heartburns' , at line 202 column 26.&lt;BR /&gt;id_no=8 symptom_no=1 symptom=Heartburns FIRST.id_no=1 LAST.id_no=0 sympt1=. sympt2=. sympt3=.&lt;BR /&gt;sympt4=. sympt5=. i=6 last.symptom=0 _ERROR_=1 _N_=6&lt;BR /&gt;NOTE: Invalid numeric data, symptom='Tiredness' , at line 202 column 26.&lt;BR /&gt;id_no=8 symptom_no=5 symptom=Tiredness FIRST.id_no=0 LAST.id_no=1 sympt1=. sympt2=. sympt3=.&lt;BR /&gt;sympt4=. sympt5=. i=. last.symptom=0 _ERROR_=1 _N_=7&lt;BR /&gt;NOTE: Invalid numeric data, symptom='Sickness' , at line 202 column 26.&lt;BR /&gt;id_no=9 symptom_no=2 symptom=Sickness FIRST.id_no=1 LAST.id_no=0 sympt1=. sympt2=. sympt3=.&lt;BR /&gt;sympt4=. sympt5=. i=6 last.symptom=0 _ERROR_=1 _N_=8&lt;BR /&gt;NOTE: Invalid numeric data, symptom='Spasm' , at line 202 column 26.&lt;BR /&gt;id_no=9 symptom_no=3 symptom=Spasm FIRST.id_no=0 LAST.id_no=0 sympt1=. sympt2=. sympt3=. sympt4=.&lt;BR /&gt;sympt5=. i=. last.symptom=0 _ERROR_=1 _N_=9&lt;BR /&gt;NOTE: Invalid numeric data, symptom='Temperature' , at line 202 column 26.&lt;BR /&gt;id_no=9 symptom_no=4 symptom=Temperature FIRST.id_no=0 LAST.id_no=1 sympt1=. sympt2=. sympt3=.&lt;BR /&gt;sympt4=. sympt5=. i=. last.symptom=0 _ERROR_=1 _N_=10&lt;BR /&gt;NOTE: Invalid numeric data, symptom='Spasm' , at line 202 column 26.&lt;BR /&gt;id_no=10 symptom_no=3 symptom=Spasm FIRST.id_no=1 LAST.id_no=0 sympt1=. sympt2=. sympt3=. sympt4=.&lt;BR /&gt;sympt5=. i=6 last.symptom=0 _ERROR_=1 _N_=11&lt;BR /&gt;NOTE: Invalid numeric data, symptom='Tiredness' , at line 202 column 26.&lt;BR /&gt;id_no=10 symptom_no=5 symptom=Tiredness FIRST.id_no=0 LAST.id_no=1 sympt1=. sympt2=. sympt3=.&lt;BR /&gt;sympt4=. sympt5=. i=. last.symptom=0 _ERROR_=1 _N_=12&lt;BR /&gt;NOTE: Invalid numeric data, symptom='Spasm' , at line 202 column 26.&lt;BR /&gt;id_no=11 symptom_no=3 symptom=Spasm FIRST.id_no=1 LAST.id_no=0 sympt1=. sympt2=. sympt3=. sympt4=.&lt;BR /&gt;sympt5=. i=6 last.symptom=0 _ERROR_=1 _N_=13&lt;BR /&gt;NOTE: Invalid numeric data, symptom='Tiredness' , at line 202 column 26.&lt;BR /&gt;id_no=11 symptom_no=5 symptom=Tiredness FIRST.id_no=0 LAST.id_no=1 sympt1=. sympt2=. sympt3=.&lt;BR /&gt;sympt4=. sympt5=. i=. last.symptom=0 _ERROR_=1 _N_=14&lt;BR /&gt;NOTE: Invalid numeric data, symptom='Temperature' , at line 202 column 26.&lt;BR /&gt;id_no=12 symptom_no=4 symptom=Temperature FIRST.id_no=1 LAST.id_no=0 sympt1=. sympt2=. sympt3=.&lt;BR /&gt;sympt4=. sympt5=. i=6 last.symptom=0 _ERROR_=1 _N_=15&lt;BR /&gt;NOTE: Invalid numeric data, symptom='Tiredness' , at line 202 column 26.&lt;BR /&gt;id_no=12 symptom_no=5 symptom=Tiredness FIRST.id_no=0 LAST.id_no=1 sympt1=. sympt2=. sympt3=.&lt;BR /&gt;sympt4=. sympt5=. i=. last.symptom=0 _ERROR_=1 _N_=16&lt;BR /&gt;NOTE: Invalid numeric data, symptom='Spasm' , at line 202 column 26.&lt;BR /&gt;id_no=13 symptom_no=3 symptom=Spasm FIRST.id_no=1 LAST.id_no=0 sympt1=. sympt2=. sympt3=. sympt4=.&lt;BR /&gt;sympt5=. i=6 last.symptom=0 _ERROR_=1 _N_=17&lt;BR /&gt;NOTE: Invalid numeric data, symptom='Temperature' , at line 202 column 26.&lt;BR /&gt;id_no=13 symptom_no=4 symptom=Temperature FIRST.id_no=0 LAST.id_no=1 sympt1=. sympt2=. sympt3=.&lt;BR /&gt;sympt4=. sympt5=. i=. last.symptom=0 _ERROR_=1 _N_=18&lt;BR /&gt;NOTE: Invalid numeric data, symptom='Spasm' , at line 202 column 26.&lt;BR /&gt;id_no=14 symptom_no=3 symptom=Spasm FIRST.id_no=1 LAST.id_no=1 sympt1=. sympt2=. sympt3=. sympt4=.&lt;BR /&gt;sympt5=. i=6 last.symptom=0 _ERROR_=1 _N_=19&lt;BR /&gt;NOTE: Invalid numeric data, symptom='Heartburns' , at line 202 column 26.&lt;BR /&gt;WARNING: Limit set by ERRORS= option reached. Further errors of this type will not be printed.&lt;BR /&gt;id_no=15 symptom_no=1 symptom=Heartburns FIRST.id_no=1 LAST.id_no=0 sympt1=. sympt2=. sympt3=.&lt;BR /&gt;sympt4=. sympt5=. i=6 last.symptom=0 _ERROR_=1 _N_=20&lt;BR /&gt;NOTE: There were 18082 observations read from the data set WORK.LONGSORT.&lt;BR /&gt;NOTE: The data set WORK.NEW has 0 observations and 6 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.12 seconds&lt;BR /&gt;cpu time 0.07 seconds&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;205 proc print data= new;&lt;BR /&gt;206 run;&lt;/P&gt;&lt;P&gt;NOTE: No observations in data set WORK.NEW.&lt;BR /&gt;NOTE: PROCEDURE PRINT used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I realize my issue is that I need to indicate that for sympt1-5 they are character variables but I do not know how to do this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, How do I create the new variable for disease that is in the new chart?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 20:10:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415643#M101959</guid>
      <dc:creator>jessica_join</dc:creator>
      <dc:date>2017-11-22T20:10:49Z</dc:date>
    </item>
    <item>
      <title>Re: Array First.id retain last.id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415646#M101961</link>
      <description>&lt;P&gt;UPDATE&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
  set longsort;
  by id_no;
  Keep id_no sympt1 - sympt5;
  retain sympt1 - sympt5;
  array New_a (1:5) sympt1 - sympt5;
  If first.id_no then do;
    Do i = 1 to 5;
      new_a (i) = .;
    end;
  end;
  new_a (symptom_no) = symptom;
  if last.symptom then output;
run;
proc print data= new; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have this now but I need help defining sympt1-5 as character variables while ID is numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, how do I add disease as a variable as shown in the outcome I am supposed to have.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 20:32:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415646#M101961</guid>
      <dc:creator>jessica_join</dc:creator>
      <dc:date>2017-11-22T20:32:28Z</dc:date>
    </item>
    <item>
      <title>Re: Array First.id retain last.id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415656#M101964</link>
      <description>&lt;P&gt;SAS will define type and length as soon as it sees that you are using it for something.&amp;nbsp; In your current code you first define the SYMPTxx variables in the ARRAY statement.&amp;nbsp; Since you did not tell how to define the variables it made them a numeric.&amp;nbsp; You can dd a length specification to the ARRAY statement.&amp;nbsp; For example if you want them to be define as character variables with a length of 20 you could code it as.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  array New_a (5) $20 sympt1 - sympt5;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But the best way is to NOT depend on SAS guessing how you want to define a variable. Instead define it yourself using a LENGTH statement before you start using it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length sympt1 - sympt5 $20;
array New_a sympt1 - sympt5;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What does the DISEASE variable represent? If you want to set it to zero everywhere then just add an assignment statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;disease = 0;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Make sure it is not dropped.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 20:42:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415656#M101964</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-11-22T20:42:13Z</dc:date>
    </item>
    <item>
      <title>Re: Array First.id retain last.id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415667#M101969</link>
      <description>&lt;P&gt;Thank you so much with all your help. I am a sas newbie and this class has been way too much for me. I want to make sure I understand this before my exam!&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 21:07:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415667#M101969</guid>
      <dc:creator>jessica_join</dc:creator>
      <dc:date>2017-11-22T21:07:22Z</dc:date>
    </item>
    <item>
      <title>Re: Array First.id retain last.id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415671#M101970</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new; 
	set longsort; 
	by id_no; 
	Keep id_no sympt1 - sympt5 disease; 
	retain sympt1 - sympt5; 
	array New_a (1:5) $ 20 sympt1 - sympt5; 
	If first.id_no then
	do; 
	Do i = 1 to 5; 
		new_a (i) = .; 
		disease= 0; 
		end; 
	end; 
	new_a (symptom_no) = symptom; 
	if last.id then output; 
		run; 
	proc print data= new; 
	run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It is saying 0 observations&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 21:46:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415671#M101970</guid>
      <dc:creator>jessica_join</dc:creator>
      <dc:date>2017-11-22T21:46:13Z</dc:date>
    </item>
    <item>
      <title>Re: Array First.id retain last.id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415678#M101976</link>
      <description>&lt;P&gt;Please include the full log.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 21:44:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415678#M101976</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-22T21:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: Array First.id retain last.id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415679#M101977</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro one (v1,v2); 
proc import out  = &amp;amp;v1
            datafile = "\\Client\C$\Users\brian\Desktop\data\&amp;amp;v2"
            DBMS     = xlsx replace;
            getnames = YES;
run;


%mend one; 
%one (Project3, Project3_f17);
 proc format; 
value symptom_no	1= "heartburns" 
					2= "Sickness"
					3= "Spasm"
					4= "Temperature"
					5= "Tiredness"; 
		
proc sort data=Project3 out= longsort; 
 	by id_no; 
run; 

data new; 
	set longsort; 
	by id_no; 
	Keep id_no sympt1 - sympt5 disease; 
	retain sympt1 - sympt5; 
	array New_a (1:5) $ 20 sympt1 - sympt5; 
	If first.id_no then
	do; 
	Do i = 1 to 5; 
		new_a (i) = .; 
		disease= 0; 
		end; 
	end; 
	new_a (symptom_no) = symptom; 
	if last.id then output; 
		run; 
	proc print data= new; 
	run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;NOTE: The import data set has 18082 observations and 3 variables.&lt;BR /&gt;NOTE: WORK.PROJECT3 data set was successfully created.&lt;BR /&gt;NOTE: PROCEDURE IMPORT used (Total process time):&lt;BR /&gt;real time 8.72 seconds&lt;BR /&gt;cpu time 0.70 seconds&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;358 proc format;&lt;BR /&gt;359 value symptom_no 1= "heartburns"&lt;BR /&gt;360 2= "Sickness"&lt;BR /&gt;361 3= "Spasm"&lt;BR /&gt;362 4= "Temperature"&lt;BR /&gt;363 5= "Tiredness";&lt;BR /&gt;NOTE: Format SYMPTOM_NO is already on the library WORK.FORMATS.&lt;BR /&gt;NOTE: Format SYMPTOM_NO has been output.&lt;BR /&gt;364&lt;/P&gt;&lt;P&gt;NOTE: PROCEDURE FORMAT used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;365 proc sort data=Project3 out= longsort;&lt;BR /&gt;366 by id_no;&lt;BR /&gt;367 run;&lt;/P&gt;&lt;P&gt;NOTE: There were 18082 observations read from the data set WORK.PROJECT3.&lt;BR /&gt;NOTE: The data set WORK.LONGSORT has 18082 observations and 3 variables.&lt;BR /&gt;NOTE: PROCEDURE SORT used (Total process time):&lt;BR /&gt;real time 0.02 seconds&lt;BR /&gt;cpu time 0.03 seconds&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;368&lt;BR /&gt;369 data new;&lt;BR /&gt;370 set longsort;&lt;BR /&gt;371 by id_no;&lt;BR /&gt;372 Keep id_no sympt1 - sympt5 disease;&lt;BR /&gt;373 retain sympt1 - sympt5;&lt;BR /&gt;374 array New_a (1:5) $ 20 sympt1 - sympt5;&lt;BR /&gt;375 If first.id_no then&lt;BR /&gt;376 do;&lt;BR /&gt;377 Do i = 1 to 5;&lt;BR /&gt;378 new_a (i) = .;&lt;BR /&gt;379 disease= 0;&lt;BR /&gt;380 end;&lt;BR /&gt;381 end;&lt;BR /&gt;382 new_a (symptom_no) = symptom;&lt;BR /&gt;383 if last.id then output;&lt;BR /&gt;384 run;&lt;/P&gt;&lt;P&gt;NOTE: Numeric values have been converted to character values at the places given by:&lt;BR /&gt;(Line):(Column).&lt;BR /&gt;378:9&lt;BR /&gt;NOTE: Variable last.id is uninitialized.&lt;BR /&gt;NOTE: There were 18082 observations read from the data set WORK.LONGSORT.&lt;BR /&gt;NOTE: The data set WORK.NEW has 0 observations and 7 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.04 seconds&lt;BR /&gt;cpu time 0.04 seconds&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;385 proc print data= new;&lt;BR /&gt;386 run;&lt;/P&gt;&lt;P&gt;NOTE: No observations in data set WORK.NEW.&lt;BR /&gt;NOTE: PROCEDURE PRINT used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 21:47:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415679#M101977</guid>
      <dc:creator>jessica_join</dc:creator>
      <dc:date>2017-11-22T21:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: Array First.id retain last.id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415689#M101981</link>
      <description>&lt;P&gt;Look at the first two notes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have a typo, first.id rather than first.id_no&lt;/P&gt;
&lt;P&gt;And I think the character array should be $20 -&amp;gt; no space.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;The first note about conversion is saying that it still thinks the array is numeric for some reason, note the number in the error that can be linked to the line itn the log. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 21:57:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415689#M101981</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-22T21:57:33Z</dc:date>
    </item>
    <item>
      <title>Re: Array First.id retain last.id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415697#M101986</link>
      <description>It’s not a huge deal, but you should probably mark one of Tom’s answer as correct, he provided more help and better answers than I did here :). &lt;BR /&gt;</description>
      <pubDate>Wed, 22 Nov 2017 22:16:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415697#M101986</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-22T22:16:16Z</dc:date>
    </item>
    <item>
      <title>Re: Array First.id retain last.id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415699#M101988</link>
      <description>&lt;P&gt;Ooops thank you. I thought it was Toms post. Thank you for your help as well!&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 22:23:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415699#M101988</guid>
      <dc:creator>jessica_join</dc:creator>
      <dc:date>2017-11-22T22:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: Array First.id retain last.id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415719#M102002</link>
      <description>&lt;P&gt;Now that you have made some progress perhaps you can explain in more detail the overall picture.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looking at your final program and the 15 sample records you posted it looks like you really only have TWO variables in your source table. The SYMPTOM and SYMPTOM_NO fields have the same information.&amp;nbsp; When SYMPTOM_NO=1 then SYMPTOM is always equal to "Heartburns".&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
 infile cards truncover ;
 input id_no symptom_no symptom $20. ;
cards;
1 1 Heartburns
1 2 Sickness
4 5 Tiredness
6 1 Heartburns
7 4 Temperature
8 1 Heartburns
8 5 Tiredness
9 2 Sickness
9 3 Spasm
9 4 Temperature
10 3 Spasm
10 5 Tiredness
11 3 Spasm
11 5 Tiredness
12 4 Temperature
12 5 Tiredness
13 3 Spasm
13 4 Temperature
14 3 Spasm
15 1 Heartburns
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So what is it that you want to calculate in the data step?&amp;nbsp; Do you want to count how many times a given ID got a particular symptom? Perhaps you want to use the symptom names as the variable names in your array?&amp;nbsp; &amp;nbsp;Also what is this DISEASE variable you mentioned?&amp;nbsp; Is that something you are supposed to calculate?&amp;nbsp; Is it the count of how many records each ID had?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps you want something like this?&lt;/P&gt;
&lt;P&gt;This is an example of what is called a DOW loop.&amp;nbsp; It eliminates the need for retaining variables or an OUTPUT statement since it processes all of the records for a given BY group in the same iteration of the data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  do until (last.id_no);
    set have ;
    by id_no;
    array counts Heartburns Sickness Spasm Temperature Tiredness ;
    if first.id_no then do _n_=1 to dim(counts);
       counts(_n_)=0;
    end;
    counts(symptom_no)=counts(symptom_no)+1;
    disease=sum(disease,1);
  end;
  keep id_no Heartburns Sickness Spasm Temperature Tiredness Disease ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 520px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/16811iA97B1564E513FD8C/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Nov 2017 00:32:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-First-id-retain-last-id/m-p/415719#M102002</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-11-23T00:32:25Z</dc:date>
    </item>
  </channel>
</rss>

