Wooah – We’re Halfway There!

6

For those of you who were growing up in the 80’s and listening to rock with hair that had been teased for hours on end and using an entire bottle of AquaNet in the process, and pant legs pegged so tight you had bruises around your ankles, that line should be familiar. Or, maybe you preferred to get decked out in neon from head to toe, like the author (see photo)! But regardless of what you wore, maybe you know that line. No? Well, it comes from Bon Jovi’s number 1 hit from 1986, Livin’ on a Prayer. Were YOU programming in 1986?!? And, what does this have to do with certification, you ask? Stacey and are half-way through the SAS Certification Prep Guide book! This week’s assignment - Reading SAS Data Sets.

Some of the concepts were grasped easier than others and the questions regarding direct access got a little tricky, which is something we’re accustomed to at this point. Below is one of the questions regarding direct access. Unfortunately, I missed this one.

Assuming that the data set Company.USA has five or more observations, what is the result of submitting the following program?

     Data work.getobs5 (drop=obsnum);
          Obsnum=5;
          Set company.usa (keep= manager payroll) point=obsum;
          Output;
          Stop;
     Run;

  1. An error
  2. An empty data set
  3. A continuous loop
  4. A data set that contains one observation


The correct answer is D, the data set contains one observation. The reason, according to the handy answer key, is that only one observation was created when we combined the OUTPUT and STOP statements with the POINT= option. I’m still looking for a little clarification on that as the concept hasn’t quite sunken in yet. Any takers?

In the words on Jon Bon Jovi, we’re Livin’ on a Prayer here but at least we’re halfway there! Until next time dear readers.

Share

About Author

Christine Kjellberg

Sr Associate Development Tester

6 Comments

  1. Prashant Chegoor on

    Christine and Stacey please note that certain errors/typos in the book
    "SAS Certification Prep Guide: Base Programming for SAS 9, Second Edition " have been updated here recently:
    http://support.sas.com/publishing/basecertguide.html
    Also i don't know if this can be regarded as a error but on Page 672 Chapter 22 in Quiz 4 datastep the informat for the variable 'Supplier' should be & $15. instead of : $15. since the Values of 'Supplier' have a single embedded blank.

  2. Christine Kjellberg on

    Prashant, thank you so much for the clarification! I really appreciate you taking the time to explain that to me - and others who maybe are struggling with it also.

  3. Stacey Hamilton on

    Thank you, Prashant! I had the same trouble as Christine (actually more trouble). After reading your explanation, I think I finally get it.

  4. Prashant Chegoor on

    Excuse me for the typo above , the following is what i meant above ,
    "Also a slight variation of the above dataset is as follows"

  5. Prashant Chegoor on

    Hello Christine,
    Let me provide some clarification on your Query above.
    Data work.getobs5 (drop=obsnum);
    Obsnum=5;
    Set company.usa (keep= manager payroll) point=obsum;
    Output;
    Stop;
    Run;
    In the above datastep:
    Work.getobs5= Output Dataset
    Company.usa=Input Dataset
    The POINT =obsnum option in the Set Statement of the above data set allows you to read that particular observation number represented by Obsnum.In this case Obsnum=5 and since the input dataset Company.usa has atleast 5 observations the 5th observation is read from the data set Company.usa.
    Now the OUTPUT Statement which follows the Set Statement will output this as the First Observation in the output dataset work.getobs5.When you are using an OUTPUT statement you are telling SAS to output as an obesrvation whatever information there is till that point into an output dataset. Since the Set Statement has read only the 5th observation ,only one observation is written to the work.getobs5 dataset ( ie 5th obervation of company.usa). Also OUTPUT statement overides the implicit output statement present at the bottom of any data step.This is because as u know usually observations are written to dataset at the bottom of the data step.
    Generally SAS continues to read data from a dataset or a file until the end of file is reached, ie there are no more records present and this usually occurs when SAS reads the records sequentially from the input file or dataset. Suppose that there was no STOP statement in the above datastep ,after the execution of the OUTPUT statement the datastep control would return to the top to execute the set statement again ouput a observation in the output dataset .This would result in data step entering into a continous loop because it is not sure where to STOP because each time it executes the set statement it reads only the 5 observation . Therefore we need the STOP statement to tell SAS to terminate after the Outputting the first obervation in the work.getob5.
    Also a slight of the above dataset is as follows:
    Data work.getobs5;
    Set company.usa (keep= manager payroll first obs=5 obs=5 );
    Run;
    In the above , the ouput dataset again has only one observation as dictated by firstobs= and obs = options in the company.usa dataset.But here we do not require a OUTPUT or a STOP statement.The firstobs = and obs= options subset the company.usa dataset to only one observation (ie the 5 th observation in company.usa).This is similar to reading from a dataset having only a single observation and outputting it into work.getobs5 dataset.
    Let me know if this helps. BTW this is a good question since the concept is a bit tricky but easy once you grasp it.

  6. Stacey Hamilton on

    You may not pass the certification exam, but you can sure pick an outfit!
    Go hair!

Back to Top