Scenario 8

Code Solution

The solution listed below is one example of a program that could be used to accomplish each task within the scenario. Your code can be different, as long as it results in the same answers.
data work.scenario8;                       /*#1*/
   set cert.addresses;                     /*#2*/
   Zipcode=substr(State,3,5);              /*#3*/
   State=substr(State,1,2);                /*#4*/
run;
proc print data=work.scenario8;            /*#5*/
   where zipcode='85069';           
run;
proc freq data=work.scenario8 order=freq;  /*#6*/
   tables State;                           /*#7*/
run;
1 The DATA step creates a temporary data set named Work.Scenario8.
2 The SET statement reads observations from one or more SAS data sets.
3 The assignment statement creates a new variable, Zipcode, which uses the SUBSTR function to extract the last 5 characters of the values in the variable State, starting at and including character 3.
4 The assignment statement replaces the value of State and uses the SUBSTR function to extract 2 characters of the values in the variable State, starting at and including character 1.
5 The PRINT procedure enables you to view the contents of the new data set, Work.Scenario8 where Zipcode is equal to 85069.
6 The FREQ procedure creates one-way, two-way, and n-way tables. It also describes data by reporting the distribution of variable values. The ORDER=FREQ option orders the table by descending frequency.
7 The TABLES statement requests a one-way frequency with the default statistics for the variable State.
Output A2.11 PROC PRINT Results
PROC PRINT Results
Output A2.12 PROC FREQ Results
PROC FREQ Results

Test Your Code Solution

  1. Correct Answer: 3
  2. Correct Answer: 45
  3. Correct Answer: 2
Last updated: February 14, 2019
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset