<?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: re: create new variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/re-create-new-variables/m-p/779643#M248349</link>
    <description>&lt;P&gt;The report has to contain the Academic Year, ID, LastName, FirstName, MiddleName, Major1, Major2, StartDate, CompletionDateand Degree.&lt;/P&gt;</description>
    <pubDate>Wed, 10 Nov 2021 20:17:27 GMT</pubDate>
    <dc:creator>twildone</dc:creator>
    <dc:date>2021-11-10T20:17:27Z</dc:date>
    <item>
      <title>re: create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-create-new-variables/m-p/779611#M248333</link>
      <description>&lt;P&gt;Hi...I am trying to create two new variables (Major1 &amp;amp; Major2) from the variable Program. What I have is that some students finish one program and start a new program in the same AcademicYear and I want to separate the program into Major1 and Major2. If the student starts a second program in the same AcademicYear, then I want that program to be entered as Major2 otherwise the program is entered as Major1. Any suggestions....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 AcademicYear $ 4 ID $ 4 Program $ 20 TermStartDate $ 8;
input AcademicYear $ ID $ Program $ TermStartDate $;
cards;

2019 0010 Hairstyling 20190901
2019 0010 Hairstyling 20200101
2019 0010 CulinaryArt 20200401
2020 0010 CulinaryArt 20200901
2020 0010 CulinaryArt 20210101
2019 0015 AutoMechanics 20190901
2019 0015 AutoMechanics 20200101
;
run;

Want:

AcademicYear	ID	Program	TermStartDate	Major1 	Major2
2019	0010	Hairstyling	20190901	Hairstyling	
2019	0010	Hairstyling	20200101	Hairstyling	
2019	0010	CulinaryArt	20200401		CulinaryArt
2020	0010	CulinaryArt	20200901	CulinaryArt	
2020	0010	CulinaryArt	20210101	CulinaryArt	
2019	0015	AutoMechanics	20190901	AutoMechanics	
2019	0015	AutoMechanics	20200101	AutoMechanics	
&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Nov 2021 17:52:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-create-new-variables/m-p/779611#M248333</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2021-11-10T17:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: re: create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-create-new-variables/m-p/779618#M248338</link>
      <description>&lt;P&gt;Often, this type of re-arranging the data is not necessary, and makes the next steps more difficult. Leaving the data as is usually makes the data easier to use in the next step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What analysis or report are you going to be creating?&lt;/P&gt;</description>
      <pubDate>Wed, 10 Nov 2021 18:17:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-create-new-variables/m-p/779618#M248338</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-10T18:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: re: create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-create-new-variables/m-p/779624#M248342</link>
      <description>&lt;P&gt;Hi Paige....I have to create a report and one of the requirements is to identify the programs that a student would have been enrolled in during each academic year as Major1 and Major2 if they have enrolled in a second program in the same academic year....hope that helps....thanks&lt;/P&gt;</description>
      <pubDate>Wed, 10 Nov 2021 18:36:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-create-new-variables/m-p/779624#M248342</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2021-11-10T18:36:07Z</dc:date>
    </item>
    <item>
      <title>Re: re: create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-create-new-variables/m-p/779626#M248344</link>
      <description>&lt;P&gt;No re-arranging is needed. What should the report look like?&lt;/P&gt;</description>
      <pubDate>Wed, 10 Nov 2021 18:54:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-create-new-variables/m-p/779626#M248344</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-10T18:54:21Z</dc:date>
    </item>
    <item>
      <title>Re: re: create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-create-new-variables/m-p/779643#M248349</link>
      <description>&lt;P&gt;The report has to contain the Academic Year, ID, LastName, FirstName, MiddleName, Major1, Major2, StartDate, CompletionDateand Degree.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Nov 2021 20:17:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-create-new-variables/m-p/779643#M248349</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2021-11-10T20:17:27Z</dc:date>
    </item>
    <item>
      <title>Re: re: create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-create-new-variables/m-p/779644#M248350</link>
      <description>With separate lines for each Major as in your example? That doesn't seem to make a ton of sense for future usage as shown to be honest.&lt;BR /&gt;2019	0010	Hairstyling	20200101	Hairstyling	&lt;BR /&gt;2019	0010	CulinaryArt	20200401		            CulinaryArt</description>
      <pubDate>Wed, 10 Nov 2021 20:19:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-create-new-variables/m-p/779644#M248350</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-11-10T20:19:07Z</dc:date>
    </item>
    <item>
      <title>Re: re: create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-create-new-variables/m-p/779649#M248354</link>
      <description>&lt;P&gt;Hi Reeza….for the example that you have identified, ID=0010 was enrolled in the 2019/20 academic year and on January 1, 2020, this student was enrolled in the Hairstyling program. However, on April 1, 2020, the student was enrolled in the CulinaryArt program which would mean that the student had finished the Hairstyling program before April 1, 2020 and started the new program of Culinary Art program on or after April 1, 2020. The academic year of 2019 starts on July 1, 2019 and ends June 30, 2020. Hope that explains this example. Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Nov 2021 20:31:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-create-new-variables/m-p/779649#M248354</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2021-11-10T20:31:53Z</dc:date>
    </item>
    <item>
      <title>Re: re: create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-create-new-variables/m-p/779674#M248368</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4061"&gt;@twildone&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The report has to contain the Academic Year, ID, LastName, FirstName, MiddleName, Major1, Major2, StartDate, CompletionDateand Degree.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Some of this probably becomes a lot easier if your Dates are actually date values.You have multiple "termstartdates". Which would be the actual Startdate for the report? And what would be the rule for Completion date? Your "dates" are all "start". So no term end date. Where is the completion date to come from?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you sure that none of these records have &lt;STRONG&gt;3&lt;/STRONG&gt; or more programs in an academic year?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code, for your very limited example, adds a MajorNumber value PER ACADEMIC YEAR to count them.&lt;/P&gt;
&lt;PRE&gt;proc sort data=have;
   by id AcademicYear TermStartDate  ;
run;
data use;
   set have;
   by  id AcademicYear TermStartDate ;
   lp=lag(program);
   retain MajorNumber;
   if first.academicyear then MajorNumber=1;
   else if program ne lp then MajorNumber+1;
   drop lp;
run;&lt;/PRE&gt;
&lt;P&gt;But without seeing a concrete example of what the actual report is supposed to contain based on the example date I am not sure of the best way to use this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where would we get "degree"? Don't see anything in your example that would indicate when a "degree" would be completed.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Nov 2021 23:42:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-create-new-variables/m-p/779674#M248368</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-11-10T23:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: re: create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-create-new-variables/m-p/779824#M248420</link>
      <description>&lt;P&gt;Hi BallardW….I am quite sure that no student would have enrolled in more than 2 programs in the same academic year because the duration of programs are between 6 and 10 months. I did edit the data to include another program for ID=0010 in AcademicYear=2019 so that there were 3 programs and ran your code and it still worked. Thank you so much.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data use;
length Major1 $ 20 Major2 $ 20;
   set have;
   by  id AcademicYear TermStartDate ;
   lp=lag(program);
   retain MajorNumber;
   if first.academicyear then MajorNumber=1;
   else if program ne lp then MajorNumber+1;
   if MajorNumber = 1 then 
   Major1 = Program; 
   else
Major2 = Program; 
   drop lp;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Nov 2021 16:13:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-create-new-variables/m-p/779824#M248420</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2021-11-11T16:13:37Z</dc:date>
    </item>
  </channel>
</rss>

