Chapter 2. Performing Advanced Queries Using PROC SQL (8) - QUIZ

  1. 1. Which PROC SQL query removes duplicate values of MemberType from the query output, so that only the unique values are listed?


    a. proc sql nodup; 

            select membertype

                from sasuser.frequentflyers;


    b. proc sql;
            select distinct(membertype)

                        as MemberType
                from sasuser.frequentflyers;


    c. proc sql;
            select unique membertype

                    from sasuser.frequentflyers 

                    group by membertype;


    d. proc sql;
            select distinct membertype

                    from sasuser.frequentflyers; 



    unique 값이라고 하면 중복된 값이 없어야겠죠? 그래서 결과값에서 중복된 값을 제거하고 싶을때 특별히 쓰는 키워드가 있습니다. DISTICT였죠. 이 단어는 열(column) 전에 들어가야 합니다!! 즉, DISTINCT 변수(열)이름!!  따라서 답은 d 입니다. 



    2. Which of the following causes PROC SQL to list rows that have no data in the Address column?

    a. WHERE address is missing

    b. WHERE address not exists

    c. WHERE address is null

    d.   both a and c 

Address라는 열에 데이타가 없는 경우를 묻고 있네요. 데이타 값이 들어가있지 않은 행을 리스트할 경우, 조건 연산자인 IS MISSING 혹은 IS NULL을 이용할 수 있습니다. NOT EXISTS 연산자는 subquery에서 사용할 수 있습니다. 그래서 답은 d 입니다! 



3. You are creating a PROC SQL query that lists all employees who have spent (or overspent) their allotted 120 hours of vacation for the current year. The hours that each employee used are stored in the existing column Spent. Your query defines a new column, Balance, to calculate each employee's balance of vacation hours.


Which query produces the report that you want?


a. proc sql;

        select name, spent,

                    120-spent as calculated Balance 

                from Company.Absences

                where balance <= 0;


b. proc sql;
        select name, spent,

                120-spent as Balance
            from Company.Absences
            where calculated balance <= 0;


c. proc sql;
        select name, spent,

                120-spent as Balance 

            from Company.Absences 

            where balance <= 0;


d. proc sql;
        select name, spent,

                120-spent as calculated Balance

             from Company.Absences
            where calculated balance <= 0; 


질문부터 봅시다. PROC SQL을 이용해서 리스트를 작성하려고 하는데요. 모든 직원의 사용한 휴가 시간과 120시간의 할당된 시간에서 쓸 수 있는 시간을 새롭게 계산해서 새로운 열 이름인 Balance로 저장하려고 합니다. 그러면 들어가야할 열 이름이 name, spent이고 balance는 120 시간에서 spent 을 뺀 값이 되겠지요. 제일 중요한건 balace라는 새로운 열은 기존에 있는 spent와 120시간의 차이의 계산된 값이 들어간다는건데요. 이럴때 CALCULATED라는 키워드가 필요하고 이 키워드는 WHERE구문에 들어가야합니다! 따라서 답은 B이예요. 



4. Consider this PROC SQL query:

proc sql;
        select flightnumber,

count(*) as Flights, 

avg(boarded) 

label="Average Boarded" 

format=3.

from sasuser.internationalflights 

group by flightnumber
having avg(boarded) > 150;


The table Sasuser.Internationalflights contains 201 rows, 7 unique values of FlightNumber, 115 unique values of Boarded, and 4 different flight numbers that have an average value of Boarded that is greater than 150. How many rows of output is generated by the query?


a. 150 

b. 7
c. 4
d. 1 


Sasuser라이브러리에 있는 internationalflights라는 데이터에는 201의 열과 7개의 FlightNumber가 있고, 115개의 유니크한 값을 가진 Boarded라는 열이 있고요. 이때 Boarded의 평균 값인 150보다 큰 값을 가진 flight numbers로는 4개가 있다고 합니다. 위에 쿼리에서 아웃풋의 행이 몇개인지 묻는데요~ 답은 C. 4개 입니다. group by 로 flightnumber로 그룹이 되어있네요. flightnumber는 총 7개가 있다고 했었죠. Having은 그룹화된 값에서 필터역할을 하는것으로 150보다 이상의 값을 가진 것만 보여달라는 뜻입니다. 150보다 큰 값을 가진건 4개라고 했으니 답은  C! 



# SAS advanced, SAS 자격증, SAS PREP GUIDE 

반응형

+ Recent posts