SAS Tutorial | Step-by-Step PROC SQL

Поділитися
Вставка
  • Опубліковано 10 чер 2024
  • This tutorial is for users wishing to learn PROC SQL in a step-by-step approach.
    PROC SQL is a powerful query language that can sort, summarize, subset, join and print results all in one step. Users who are continuously improving their analytical processing will benefit from this video. Follow along as Charu demonstrates the following elements to master PROC SQL:
    1. Understand the syntax order in which to submit queries to PROC SQL.
    2. Internalize the logical order in which PROC SQL processes queries.
    3. Manage metadata using dictionary tables.
    4. Join tables using join conditions like inner join and reflexive join.
    5. Summarize data using Boolean operations.
    Download Data Files
    Here's the data Charu uses on GitHub - github.com/CharuSAS/SQL
    Proceedings Paper - www.sas.com/content/dam/SAS/s...
    Content Outline
    00:00 - Introduction and Agenda
    00:52 - Overview of PROC SQL
    02:22 - Examining Syntax order
    07:50 - Summarizing data using the Boolean Operation
    22:31 - Managing metadata using DICTIONARY Tables and Views
    28:40 - Join Tables using Inner Join and Reflexive Join Connections
    38:42 - Logical Query Processing Order
    41:44 - Step-by-Step breakdown of SQL Phases
    Additional resources
    Resource Hub for Data Professionals - www.sas.com/sas/offers/resour...
    SAS 9.4 SQL Procedure User’s Guide - go.documentation.sas.com/?doc...
    PROC SQL Syntax Order blog - blogs.sas.com/content/sastrai...
    PROC SQL DICTIONARY Tables PDF - www.pharmasug.org/proceedings...
    Working with Subquery in the SQL Procedure paper: Zhang, Lei, Yi, Danbo - www.lexjansen.com/nesug/nesug...
    Boolean in SQL blog - blogs.sas.com/content/sastrai...
    Learn more about SAS Software
    Free SAS Online Training - www.sas.com/en_us/training/of...
    Contact SAS® - www.sas.com/en_us/contact.geo...
    SUBSCRIBE TO THE SAS USERS UA-cam CHANNEL #SASUsers #LearnSAS #SASGF
    ua-cam.com/users/SASUsers?sub_...
    ABOUT SAS
    SAS is a trusted analytics powerhouse for organizations seeking immediate value from their data. A deep bench of analytics solutions and broad industry knowledge keep our customers coming back and feeling confident. With SAS®, you can discover insights from your data and make sense of it all. Identify what’s working and fix what isn’t. Make more intelligent decisions. And drive relevant change.
    CONNECT WITH SAS
    SAS ► www.sas.com/contact
    SAS Customer Support ► support.sas.com
    SAS Communities ► communities.sas.com
    SAS Analytics Explorers ► explorers.sas.com
    Facebook ► / sassoftware
    Twitter ► / sassoftware
    LinkedIn ► / sas
    Blogs ► blogs.sas.com
    RSS ►www.sas.com/rss
  • Наука та технологія

КОМЕНТАРІ • 64

  • @sandybathwater8385
    @sandybathwater8385 2 роки тому +4

    SAS aside this is a solid SQL walkthru.

  • @angelicafrank3531
    @angelicafrank3531 2 роки тому +6

    Thank you so so much!!! I took notes, pictures and wrote down every single word you said and I really am starting to understand proc sql! Thank you so much for taking the time to do this!

    • @SASUsers
      @SASUsers  2 роки тому +2

      We're glad you enjoyed it!

  • @inTuneband
    @inTuneband 3 роки тому +3

    Fantastic tutorial. Keep going Charu 😎👍

  • @kirkpaullafler2230
    @kirkpaullafler2230 4 роки тому +9

    Fantastic presentation, Charu!

    • @CharuYoga
      @CharuYoga 4 роки тому

      thanks so much Kirk. Heading over to watch yours now.

  • @jtflypegasus
    @jtflypegasus 2 роки тому +3

    Thank you for sharing your PROC SQL tips....very wonderful teaching!

    • @SASUsers
      @SASUsers  2 роки тому

      Glad it was helpful!

  • @diegosaltes
    @diegosaltes 3 роки тому +3

    Clear, relevant, useful...just excellent!!

    • @SASUsers
      @SASUsers  2 роки тому

      Glad it was helpful!

  • @78pbmenon
    @78pbmenon 3 роки тому +3

    Detailed explanation.. Easy to understand. Thank you 😊

    • @SASUsers
      @SASUsers  3 роки тому

      Absolutely! Thanks for sharing!

  • @scoiattolosilenzioso
    @scoiattolosilenzioso 2 роки тому +2

    Very good tutorial, I found it very easy to follow and very clear. Thanks!

    • @SASUsers
      @SASUsers  2 роки тому

      Great! Emanuele, thanks for the feedback and glad you found it helpful!

  • @hareshr4902
    @hareshr4902 3 роки тому +3

    Thank you Charu. Very useful information

    • @SASUsers
      @SASUsers  3 роки тому

      Haresh, thank you so much! Glad you found it helpful!

  • @9356079
    @9356079 Рік тому +2

    Thanks this was really helpful

    • @SASUsers
      @SASUsers  Рік тому +1

      You're so welcome, Ravi! We're glad it helped, should you need any further assistance please don't hesitate to give us a shout! And, good luck!

  • @gberry32
    @gberry32 3 роки тому +4

    lovely, great

  • @EderbalFilho
    @EderbalFilho 4 роки тому +4

    Muito bom! Excelente!

    • @SASUsers
      @SASUsers  4 роки тому

      Thank you for your feedback!

  • @sameerjadhav4487
    @sameerjadhav4487 2 роки тому +2

    Really nice course this course also motivated me thanks for video

    • @SASUsers
      @SASUsers  2 роки тому

      Glad you found it helpful and thanks for tuning in!

  • @Naveenkumar-zu8nj
    @Naveenkumar-zu8nj 2 роки тому +1

    Thanks , it was really helpful

    • @SASUsers
      @SASUsers  2 роки тому

      Thanks for sharing!

  • @rahulrokade2048
    @rahulrokade2048 3 роки тому +2

    Amazing .!

    • @SASUsers
      @SASUsers  3 роки тому

      Glad you enjoyed it!

  • @scienceaddicted3431
    @scienceaddicted3431 Рік тому +1

    Thank you! I do have a question though: at minute 47:05, I don't understand why were you able to access yearhired in a group by? Group by was supposed to be the third in the priority order, so yearhired should not be accessible? What am I missing?
    Thanks a lot for considering answering. I'm a newbie in SQL, so I'm often confused :)

    • @SASUsers
      @SASUsers  Рік тому

      Thank you for your inquiry! We are checking on this for you!

    • @SASUsers
      @SASUsers  Рік тому

      See reply from the presenter below:
      I will break it down to 2 statements where Yearhired appears. First we see Yearhired on the SELECT. The SELECT is simply a request to SQL to list columns you wish to see and in what order. Here we specify 2 non summarized columns: country, year(hiredate) which is our YearHired column. And one summary column - count(*) as numemp.
      Next we see Yearhired on the GROUP BY as the 2nd column by which to group. This is of interest to us and will likely answer your question. In the GROUP BY we let SQL know that we wish to group by country and then yearhired. Thus, the SELECT in conjunction with the GROUP BY, gives us rolled up rows and summary counts for each combination of Country and yearhired ( thanks to our summarized column numemp on the SELECT).

  • @ashamalathi
    @ashamalathi 3 роки тому +2

    Hi charu,
    Both where and having is been executed before select statement but why where doesn't take a new variable created where as having takes.
    I cannot understand why is it so.
    For example count (*) as count in select statement. This count column can be accessed by having where as not by where.
    Pls explain.

    • @CharuYoga
      @CharuYoga 3 роки тому +1

      Thanks for the question Asha.
      The WHERE only has access to existing data, meaning original, unprocessed data from tables on the FROM.
      the minute data gets processed as in the COUNT(*) and has no resemblance to the original, the WHERE can no longer filter that data.
      I find a good way to remember the distinction is :
      The WHERE acts as a filter on individual rows before they are grouped.
      The HAVING acts as a filter on grouped data.
      Hope this helps understand the distinction.

    • @SASUsers
      @SASUsers  3 роки тому +1

      Checking on this for you!

  • @Viveksharma-px4ku
    @Viveksharma-px4ku 2 роки тому +1

    Hello charu..I want to learn SAS..do u also give classes separately too?

    • @SASUsers
      @SASUsers  2 роки тому

      Vivek, tell us more how you would be using SAS and your role. We do offer e-learnin and live web courses as well.

  • @gandhianyanhun9943
    @gandhianyanhun9943 3 роки тому +2

    From the syntax logical order the "groupby" and "having" come before the "select". And so the calculated column can't be used in the "where". But why are you able to use the calculated column in the "groupby" which also comes before the "select" without a syntax error? This is at the 48min of the above recording.

    • @SASUsers
      @SASUsers  3 роки тому

      We are looking into this for you.

    • @SASUsers
      @SASUsers  3 роки тому +1

      Please listen again to the whole section that starts at time stamp 41:46 with the step-by-step breakdown of SQL processing. In this section, the instructor explains that even though the SELECT clause appears first in SYNTAX coding order, the WHERE clause is actually processed by SQL before the SELECT clause. So, at the point in time when SQL is executing the SELECT, the new column name has not been created yet. This is why the approach shown in the code example (to use a date constant) or the alternate approach of moving the YEAR function to the WHERE would work. Another possibility would have been to use the "calculated" keyword with the new column name.
      The "calculated" keyword helps SQL understand that this is a calculation that must be pulled from the SELECT. And in fact, if the instructor had used the calculated keyword on the WHERE clause (SQL would perform the calculation on the WHERE). Both the WHERE & The GROUP BY can access newly built columns on the SELECT that don’t already exist on the table listed on the FROM. In this example that you mentioned, the instructor didn’t use the calculated keyword on the GROUP BY, and SQL accepts that syntax without explicitly using "calculated", but SQL is still going to perform the calculation on the GROUP BY even though it’s the 3rd logical step SQL executes before the SELECT.
      It is important to remember that the coding order of the clauses is NOT the same as the execution order. That is one of the important points of this last section in the video. For more information about SQL processing, we have 2 classes you might want to look at:
      SQL 1: Essentials 2.sas.com/6055HOmmX
      SQL Methods and More 2.sas.com/6056HOmmk
      And, here’s a Community Forum link that also talks about this. 2.sas.com/6057HOmmZ

    • @evangeliaathanasiadou8828
      @evangeliaathanasiadou8828 3 роки тому

      I had the same question.. Perhaps, she made a mistake by adding "yearhired" in the GROUP BY command

    • @SASUsers
      @SASUsers  3 роки тому

      As shown at time stamp 44:39 - 45:30, you can see when the presenter runs the code that, it is a mistake to use YEARHIRED in the WHERE clause because she explains in the video that the FROM is executed first and then the WHERE is executed next. At the point in time when the WHERE is executed, YEARHIRED has not been calculated yet so it is not available to the WHERE. However, as shown at time stamp 47:09 when she runs the GROUP BY code that lists YEARHIRED, you can see that it works to have YEARHIRED in the GROUP BY clause. At the point in time when the GROUP BY is being executed, the YEARHIRED variable has already been created. To learn more about SQL processing with SAS, we recommend our SQL 1 class, as described here: 2.sas.com/6053HZeRH .

  • @kennzimaalearnings826
    @kennzimaalearnings826 2 роки тому

    Full SAS Sessions :-
    ua-cam.com/play/PLCmzhzAgjyBwafMtp7Fm7ZJj1oiwn1U5V.html

  • @shenwaskijeff3388
    @shenwaskijeff3388 3 роки тому +2

    sorry but I still don't know what's the function of the dictionary table or in which situation we should use it when managing data?

    • @SASUsers
      @SASUsers  3 роки тому

      We're checking on this for you, Shenwaski, and will get back to you soon!

    • @SASUsers
      @SASUsers  3 роки тому

      Hello again, Shenwaski, and thanks for your question about dictionary tables in SAS!
      If you scroll up to the information section below this video and click on "SHOW MORE", you will see, under "Additional Resources", a link for "PROC SQL DICTIONARY Tables PDF", which is a conference paper by our own Charu Shankar: "Know Thy Data: Techniques for Data Exploration" 2.sas.com/6054GASwp
      This paper will help you "learn to employ powerful PROC SQL’s dictionary tables to easily explore aspects of your metadata." It also explains what dictionary tables are, and gives several examples of how and why you might want to use them. "Dictionary tables contain a wealth of information about your SAS session. They are special read-only PROC SQL tables or views. They are created upon SAS invocation, updated automatically by SAS and are available throughout a SAS session. They provide information about SAS libraries, SAS data sets, SAS system options, and external files that are associated with the current SAS session and much, much more."
      Here is another paper that might help: "How Do I Look it Up If I Cannot Spell It: An Introduction to SAS Dictionary Tables" 2.sas.com/6055GASwV
      Our SAS documentation on the topic may also be helpful:
      1) DICTIONARY Tables (from "SAS 9.4 Language Reference: Concepts, Sixth Edition") 2.sas.com/6056GASwn
      2) DICTIONARY Tables (from "SAS 9.4 FedSQL Language Reference, Fifth Edition") 2.sas.com/6057GASwX
      Please let us know if we can help you with anything else!

  • @niteshsingh4377
    @niteshsingh4377 3 роки тому +2

    after learning this tutorial what i will be capable of?

    • @SASUsers
      @SASUsers  3 роки тому +2

      Users who are continuously improving their analytical processing will benefit from this video. Follow along as Charu demonstrates the following elements to master PROC SQL:
      1. Understand the syntax order in which to submit queries to PROC SQL.
      2. Internalize the logical order in which PROC SQL processes queries.
      3. Manage metadata using dictionary tables.
      4. Join tables using join conditions like inner join and reflexive join.
      5. Summarize data using Boolean operations.

  • @somcana
    @somcana Рік тому

    What if you have a date to dichotomize like you did for the mangers and employees?

    • @SASUsers
      @SASUsers  Рік тому

      Thank you for your inquiry! We are checking on this for you!

    • @kathykiraly3830
      @kathykiraly3830 Рік тому +1

      You would list your date variable in the GROUP BY clause.

  • @gopithammaboina1670
    @gopithammaboina1670 2 роки тому +1

    is it possible to retain charecter variables in pdv

    • @SASUsers
      @SASUsers  2 роки тому

      Gopi, thank you for your inquiry! We are checking on this for you!

    • @SASUsers
      @SASUsers  2 роки тому

      Gopi, SAS SQL does not have a PDV, therefore you do not have the ability to retain variable values like you do with the DATA step. SAS SQL has a powerful subroutine, the SQL Optimizer, that decides how the SQL query should be executed in order to minimize run time. The Optimizer examines submitted SQL code and characteristics of the SAS system and then creates efficient executable statements for the submitted query.
      There was a SUGI paper written about the SQL Optimizer years ago, but not sure if you want to reference it. For beginners, it may be over their head, but adding it here for your reference: The SQL Optimizer Project: _Method and _Tree in SAS®9.1 in case you want to look over it and see if you wish to add this as a reference.

  • @ashishrathore6860
    @ashishrathore6860 3 роки тому +1

    which dataset are you using

    • @SASUsers
      @SASUsers  3 роки тому

      You can find the data used for this tutorial on GitHub 2.sas.com/6051GeNyJ.

    • @SASUsers
      @SASUsers  3 роки тому

      Also, the associated paper in resources details where to download the data sets.

  • @shortsmain6971
    @shortsmain6971 2 роки тому +1

    So is SAS and SQL two seperate things... Like SAS and python??

    • @SASUsers
      @SASUsers  2 роки тому

      Thank you for you inquiry! Yes, SAS and SQL are both programming languages.

    • @SASUsers
      @SASUsers  2 роки тому

      Sharing more feedback: SQL is the acronym for for Structured Query Language. SQL is an ANSI standard language that is used for querying and reporting on data that is stored in relational databases. Most software vendors will have some implementation of SQL that you can use with their databases. The vendors usually all support the ANSI standard for SQL and then add their own features to further enhance their implementation of SQL. So, for example, Oracle SQL and Microsoft SQL Server SQL will all share features of the ANSI standard, but they might have features that are unique to their database and relational database manager software. For example this article explains in a lot of detail about the differences between these 2 SQL "flavors": 2.sas.com/6055JhSDZ

  • @sreejapesala6117
    @sreejapesala6117 Рік тому

    How to define sex variable as f = female and m= male in proc SQL program what is the code for that

    • @SASUsers
      @SASUsers  Рік тому

      We'll check on this for you and get back to you. In the meantime, you may wish to search for an answer or post your question in our SAS Support Communities.
      For example, this post may be helpful: How to create variables in PROC SQL? 2.sas.com/6051MUCDZ
      If you need to post your question, please read this: How to get fast, helpful answers 2.sas.com/6052MUCDw

    • @SASUsers
      @SASUsers  Рік тому

      Hello again, Sreeja!
      This video is approximately one hour of SQL topics. By comparison, our SAS SQL 1: Essentials class 2.sas.com/6050MqRfC is two days long with approximately 14 hours of lecture, demo, and hands-on practice. We cover how to create variables in the class in more depth.
      To create new variables, when working with an existing table or when creating a new table, you'll need to use the CASE expression. While we can't post code or screen shots here, our CASE Expression documentation (in our SAS SQL Procedure User's Guide) has two examples of how to create a new variable REGION from the existing variable CONTINENT here 2.sas.com/6051MqRfh
      We hope that helps!