<?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: Data Step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-Step/m-p/671638#M201708</link>
    <description>&lt;P&gt;Some more questions.&lt;/P&gt;
&lt;P&gt;None of your example data has any value for LEVEL. So what actual role does this play in the process? If it has one you need to include data that shows it. Otherwise I would say that your need for using LEVEL in the BY process is not needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the example you show you also do not want TERM in the by process though the data likely needs to be in the correct order.&lt;/P&gt;
&lt;P&gt;For the example data this seems to do what is requested. Note that I added "newintake" as the calculated value and left in your example data set intake.&lt;/P&gt;
&lt;PRE&gt;data want;
   set have ;
   by StudentUID Programs  AcademicYearBeg2;
   length newintake $ 10.;
   comp= lag(AcademicYearBeg2);
   if first.Programs then newintake='Initial';
   else if AcademicYearBeg2=comp then   newintake='Initial';
   else   newintake='Continued';
   drop comp;
run;
&lt;/PRE&gt;
&lt;P&gt;Since you comparison is based on the AcademicYearBeg2 using the Lag function to get the previous for comparison with the current.&lt;/P&gt;</description>
    <pubDate>Wed, 22 Jul 2020 22:48:39 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-07-22T22:48:39Z</dc:date>
    <item>
      <title>Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Step/m-p/671610#M201697</link>
      <description>&lt;P&gt;Hi....I am trying to identify records that are either "Initial" or "Continued' based on the by grouping variables. From the code I am using below, I am getting only the first row as 'Initial' and because it is possible to have duplicates based on the by grouping variables, I would like these duplicates to indicate 'Initial'. Not sure how to do this...thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data List100;
	set List100;
	length Intake $10;
	by StudentUID Programs Level AcademicYearBeg2;
		if (first.StudentUID and first.Programs and first.Level and first.AcademicYearBeg2) then
			Intake = 'Initial';
		else
			Intake = 'Continued';
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Jul 2020 20:36:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Step/m-p/671610#M201697</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2020-07-22T20:36:29Z</dc:date>
    </item>
    <item>
      <title>Re: Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Step/m-p/671614#M201698</link>
      <description>&lt;P&gt;Example data please.&lt;/P&gt;
&lt;P&gt;And what the expected output should be for that example.&lt;/P&gt;
&lt;P&gt;Hint: only include variables needed and enough records to show different types of use cases.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What 'continues'? I might think the year would be a candidate. Which, from your BY statement might mean that you actually don't want First.AcademicBegYear2 and almost certainly do not want First.StudentUID&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2020 20:54:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Step/m-p/671614#M201698</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-07-22T20:54:23Z</dc:date>
    </item>
    <item>
      <title>Re: Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Step/m-p/671634#M201704</link>
      <description>&lt;P&gt;Hi...Continued refers to when the student will continue to take the same program in the following academic year/s whereas Initial refers to the first time the student is enrolled in the program. Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
    length StudentUID 8 Programs $ 18 Level $ 1 Term $ 6 AcademicYearBeg2 $ 7 Intake $ 9;
    format StudentUID best12. Programs $char18. Level $char1. Term $char6. AcademicYearBeg2 $char7. Intake $char9.;
    informat StudentUID best12. Programs $char18. Level $char1. Term $char6. AcademicYearBeg2 $char7. Intake $char9.;
    infile datalines4 dlm='7f'x missover dsd;
    input StudentUID : best32. Programs : $char18. Level : $char1. Term : $char6. AcademicYearBeg2 : $char7. Intake : $char9.;
datalines4;
67684&amp;#127;Industrial Welding&amp;#127; &amp;#127;Winter&amp;#127;2016/17&amp;#127;Initial
67684&amp;#127;Industrial Welding&amp;#127; &amp;#127;Spring&amp;#127;2016/17&amp;#127;Continued
67684&amp;#127;Industrial Welding&amp;#127; &amp;#127;Fall&amp;#127;2017/18&amp;#127;Continued
67685&amp;#127;AutoMechanics&amp;#127; &amp;#127;Fall&amp;#127;2016/17&amp;#127;Initial
67685&amp;#127;AutoMechanics&amp;#127; &amp;#127;Winter&amp;#127;2016/17&amp;#127;Continued
67685&amp;#127;AutoMechanics&amp;#127; &amp;#127;Spring&amp;#127;2016/17&amp;#127;Continued
67685&amp;#127;AutoMechanics&amp;#127; &amp;#127;Fall&amp;#127;2017/18&amp;#127;Continued
;;;;

Want:
StudentUID Programs Level Term	AcademicYearBeg2  Intake
67684	Industrial Welding		Winter	2016/17	Initial
67684	Industrial Welding		Spring	2016/17	Initial
67684	Industrial Welding		Fall	2017/18	Continued
67685	AutoMechanics		Fall	2016/17	Initial
67685	AutoMechanics		Winter	2016/17	Initial
67685	AutoMechanics		Spring	2016/17	Initial
67685	AutoMechanics		Fall	2017/18	Continued
&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Jul 2020 22:28:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Step/m-p/671634#M201704</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2020-07-22T22:28:31Z</dc:date>
    </item>
    <item>
      <title>Re: Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Step/m-p/671638#M201708</link>
      <description>&lt;P&gt;Some more questions.&lt;/P&gt;
&lt;P&gt;None of your example data has any value for LEVEL. So what actual role does this play in the process? If it has one you need to include data that shows it. Otherwise I would say that your need for using LEVEL in the BY process is not needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the example you show you also do not want TERM in the by process though the data likely needs to be in the correct order.&lt;/P&gt;
&lt;P&gt;For the example data this seems to do what is requested. Note that I added "newintake" as the calculated value and left in your example data set intake.&lt;/P&gt;
&lt;PRE&gt;data want;
   set have ;
   by StudentUID Programs  AcademicYearBeg2;
   length newintake $ 10.;
   comp= lag(AcademicYearBeg2);
   if first.Programs then newintake='Initial';
   else if AcademicYearBeg2=comp then   newintake='Initial';
   else   newintake='Continued';
   drop comp;
run;
&lt;/PRE&gt;
&lt;P&gt;Since you comparison is based on the AcademicYearBeg2 using the Lag function to get the previous for comparison with the current.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2020 22:48:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Step/m-p/671638#M201708</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-07-22T22:48:39Z</dc:date>
    </item>
  </channel>
</rss>

