Computing the Date after a Number of Intervals - SAS Programming

The companion function to INTCK is the INTNX function.This function returns a SAS date value which is a given number of intervals after a base date value. Suppose you want to find the date 10 months after a patient's initial visit so a follow-up office visit can be arranged.Working from the initial visit date, VISIT, you can easily generate the date 10 months hence as:

FOLLOWUP=INTNX ('MONTH',VISIT,10);

For example,if the date of VISIT is 10/21/94,the FOLLOWUP date will be August 1,1995.Once again, realize that this function,like INTCK,works with internal boundaries (in this case,the 1st of each month).As long as you are fully cognizant of what the code is doing, you can't go wrong. Remember one of Murphy's laws: When working toward solving a problem, it always helps when you know the answer.

Problems

  1. You have an instream raw data file of patient hospital stays with the following file layout:
  2. Computing the Date after a Number of Intervals

      a) Write a program to create a SAS data set called DATES 1, and list the resulting data set with PROC PRINT. Create variables ID, ADMIT, DISCH, and DOB from the given data, and also create the following new variables: AGE age in years on the date of admission (as of the last birthday)
      DAY numeric day of the week of admission date (l=Sun, 2=Mon, etc.)
      MONTH numeric month of year of admission date (l=Jan, 2=Feb, etc.)

      Set up the DATA step so that the variables print with the following formats:

      ADMIT mm/dd/yy
      DISCH mm/dd/yy
      DOB ddMMMyyyy
      AGE no decimals
      DAY 3 letter names (SUN, MON, etc.)
      MONTH numeric (1=Jan, 2=Feb, etc.)

      b) Compute the mean age of all patients (use PROC MEANS — see Chapter 10, "PROC MEANS and PROC UNIVARIATE").

      c) Create a chart showing the frequency of admissions by day of week (use PROC CHART—see Chapter 12, "PROC CHART").

      d) Compute frequencies on the number of visits by month of year (use PROC FREQ — see Chapter 10).

  3. You have a SAS data set, DATES2,that contains variables MONTH and YEAR (of birth)but not day. Create a new data set based on DATES2 and include AGE as of the date the program is run, using the 15th of the month as an approximate day for the date of birth. Round the value of AGE in years to the nearest year. Store the MMDDYY8. format with DOB.
  4. You have a SAS data set, DATES3,which contains the variables ID, DOB (date of birth), VISIT_D, VISIT_M, and VISIT_Y(visit day, month, and year respectively). Write a program to create a new data set which includes a variable called AGE (approximate age rounded to the nearest year at the time of visit.) Try to calculate the value of AGE with one statement.
  5. You have a set of raw data showing the number of crayons produced at Company X on certain sample dates. The company started producing crayons in the beginning of 1990. Here is the raw data file layout:
  6. Computing the Date after a Number of Intervals

    You want to compute the mean number of crayons produced in each quarter, starting from 01/01/90. For example, the mean number of crayons produced in quarter 0 (from 01/01/90 to 03/31/90) is 12,550.There are various ways to do this, but try using the INTCK function.Also, see Chapter 10 for the syntax for PROC MEANS.

  7. You are assigned the job of "match-making" for a dating firm. The firm has its data in a SAS data set called CLIENTS, consisting of variables ID (ID number),GENDER (M or F),and DOB (date of birth.)The astrologer on staff suggests that there are two compatible groups of clients, one being males born on a Wednesday or Thursday in either January or March, and the other being females born on Fridays in either August or September.First, write a program to create a subset of CLIENTS which contains clients fitting the astrologer's suggestions. Next, print out two lists, one for females and one for males,listing the clients by ID and showing the DOB, the DAY of the week on which they were born,and the MONTH of the year in which they were born.
  8. Part of Clients data set


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

SAS Programming Topics