<?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: PROC SQL SELECT question in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-SELECT-question/m-p/549090#M74466</link>
    <description>&lt;P&gt;To me, it looks like that last step should be&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL; 
     CREATE TABLE Earliest_Grade AS 
     SELECT StudentID, TestID, grade, year(Grade_date) AS grade_year 
     FROM All_Grades
     GROUP BY StudentID
     HAVING grade_date = min(grade_date); 
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and the comments syntax should be converted into proper SAS.&lt;/P&gt;</description>
    <pubDate>Sun, 07 Apr 2019 04:16:09 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2019-04-07T04:16:09Z</dc:date>
    <item>
      <title>PROC SQL SELECT question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-SELECT-question/m-p/549073#M74464</link>
      <description>&lt;P&gt;I am new to SAS and have been working on some exercises, but don't know if my code is correct. I have three data sets and need to combine all three into one and then create a new one with only unique records.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are the variable definitions and my code:&lt;/P&gt;&lt;PRE&gt;SAS Dataset Name: STUDENTS
Column Name	Type	Format	
First_name	Text	$30.	
Last_name	Text	$30.	
DOB		Text	mmddyy10.
StudentID	Text	$5.	

SAS Dataset Name: COURSES
Column Name	Type	Format	
StudentID	Text	$5.	
CourseID	Text	$8.	
Course_name	Text	$30.
Begin_date	Number	mmddyy10.
End_date	Number	mmddyy10.
TestID	        Text	$10.	

SAS Dataset Name: GRADES
Column Name	Type	Format	
TestID		Text	$10.	
Test_type	Text	$5.	
Grade		Number  +3.	
Grade_date	Number	Mmddyy10.	
	

// Put all results from the three tables into one table

PROC SQL;
CREATE TABLE All_Grades AS 
      SELECT Students.*, Courses.*, Grades.* 
      FROM Students, Courses, Grades
      WHERE Students.StudentID = Courses.StudentID AND Courses.TestID = Grades.TestID;
quit;

// From the previous combined table, select unique student IDs with their the earliest test grade expressed as a year

PROC SQL; 
     CREATE TABLE Earliest_Test AS 
     SELECT DISTINCT StudentID, TestID, MIN(Test_date) num AS test_year format=YEAR4
     FROM All_Grades
     ORDER BY StudentID ; 
quit;&lt;/PRE&gt;</description>
      <pubDate>Sat, 06 Apr 2019 22:49:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-SELECT-question/m-p/549073#M74464</guid>
      <dc:creator>jrsm21</dc:creator>
      <dc:date>2019-04-06T22:49:09Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL SELECT question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-SELECT-question/m-p/549074#M74465</link>
      <description>&lt;P&gt;So what is your question? Do you have some reason to believe the code is incorrect? Are you getting errors or issues with the results?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's some improvement suggestions but I suspect your answer is fine.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Listing tables separated via a comma is a cross join, which is filtered via the WHERE. You may want to explicitly define the type of joins you want instead of letting SAS figure it out. Your log may indicate that as well - check if there's a note in it.&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;Check the number of records and determine how many should have at the end and verify that's what you're getting. I suspect you need as many records as in GRADES in your final data set but that could depend on the logic of how the data is collected, which I do not know.&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;I think format=year4 should have a period at the end to define the format, but if it's causing issues I'm wrong.&amp;nbsp;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given lack of data or context, I'm guessing a lot here.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/269619"&gt;@jrsm21&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am new to SAS and have been working on some exercises, but don't know if my code is correct. I have three data sets and need to combine all three into one and then create a new one with only unique records.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are the variable definitions and my code:&lt;/P&gt;
&lt;PRE&gt;SAS Dataset Name: STUDENTS
Column Name	Type	Format	
First_name	Text	$30.	
Last_name	Text	$30.	
DOB		Text	mmddyy10.
StudentID	Text	$5.	

SAS Dataset Name: COURSES
Column Name	Type	Format	
StudentID	Text	$5.	
CourseID	Text	$8.	
Course_name	Text	$30.
Begin_date	Number	mmddyy10.
End_date	Number	mmddyy10.
TestID	        Text	$10.	

SAS Dataset Name: GRADES
Column Name	Type	Format	
TestID		Text	$10.	
Test_type	Text	$5.	
Grade		Number  +3.	
Grade_date	Number	Mmddyy10.	
	

// Put all results from the three tables into one table

PROC SQL;
CREATE TABLE All_Grades AS 
      SELECT Students.*, Courses.*, Grades.* 
      FROM Students, Courses, Grades
      WHERE Students.StudentID = Courses.StudentID AND Courses.TestID = Grades.TestID;
quit;

// From the previous combined table, select unique student IDs with their the earliest test grade expressed as a year

PROC SQL; 
     CREATE TABLE Earliest_Test AS 
     SELECT DISTINCT StudentID, TestID, MIN(Test_date) num AS test_year format=YEAR4
     FROM All_Grades
     ORDER BY StudentID ; 
quit;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 06 Apr 2019 22:58:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-SELECT-question/m-p/549074#M74465</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-04-06T22:58:46Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL SELECT question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-SELECT-question/m-p/549090#M74466</link>
      <description>&lt;P&gt;To me, it looks like that last step should be&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL; 
     CREATE TABLE Earliest_Grade AS 
     SELECT StudentID, TestID, grade, year(Grade_date) AS grade_year 
     FROM All_Grades
     GROUP BY StudentID
     HAVING grade_date = min(grade_date); 
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and the comments syntax should be converted into proper SAS.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Apr 2019 04:16:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-SELECT-question/m-p/549090#M74466</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-04-07T04:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL SELECT question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-SELECT-question/m-p/549093#M74467</link>
      <description>'unique' records is ambiguous in this situation. Is a unique record one per test, one per course or one per student?</description>
      <pubDate>Sun, 07 Apr 2019 04:21:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-SELECT-question/m-p/549093#M74467</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-04-07T04:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL SELECT question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-SELECT-question/m-p/549095#M74468</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Sun, 07 Apr 2019 04:22:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-SELECT-question/m-p/549095#M74468</guid>
      <dc:creator>jrsm21</dc:creator>
      <dc:date>2019-04-07T04:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL SELECT question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-SELECT-question/m-p/549098#M74469</link>
      <description>&lt;P&gt;Only one course record for each student. It should be the test record with the earliest test_date.&lt;BR /&gt;Only the variables StudentID, CourseID, Test_date, and Grade should be included in Earliest_Test data table. The test_year variable should contain the test_date year.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Apr 2019 04:36:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-SELECT-question/m-p/549098#M74469</guid>
      <dc:creator>jrsm21</dc:creator>
      <dc:date>2019-04-07T04:36:48Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL SELECT question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-SELECT-question/m-p/549165#M74474</link>
      <description>Regardless of test type?</description>
      <pubDate>Mon, 08 Apr 2019 04:03:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-SELECT-question/m-p/549165#M74474</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-04-08T04:03:48Z</dc:date>
    </item>
  </channel>
</rss>

