Scenario-1: You have been given a data file named “he_data1.csv”, please accomplish the following activity and provide the answer.

  • Load this file as fileref ‘he_data’
  • Create a temporary dataset named ‘he_data1’
  • Create another temporary dataset named ‘he_data1_new’ and add another feature which provide the total fee by applying the 18% tax on the course fee.
  • Now answer following questions

Question-1: What is the total fee in observation-7 in dataset “he_data1_new”?

Answer: 531

Question-2: What is the total fee in observation-7

Answer: 481

Question-3: How can you add “MaxEndDate” variable in each observation having value as 03/31/20.

  1. var MaxEndDate='31Mar2020'd;

   format MaxEndDate mmddyy8.;

  1. MaxEndDate='31Mar2020'd;

   informat MaxEndDate mmddyy8.;

  1. MaxEndDate='31/03/2020'd;

   format MaxEndDate mmddyy8.;

  1. MaxEndDate='31Mar2020'd;

   format MaxEndDate mmddyy8.;

 

Answer: D

Explanation: You can use a separate FORMAT statement for each variable, or you can format several variables (using either the same format or different formats) in a single FORMAT statement.

format date mmddyy8.;  

associates the format MMDDYY8. with the variable Date as example 03/31/20 (8 character including 2 ‘/’)                                                                                        

 

Solution:

*Create a File Reference for the csv file;

FILENAME he_data '/folders/myfolders/he_sas/he_data1.csv' ;

run;

 

* Import the fileref as SAS data set;

PROC IMPORT DATAFILE=he_data DBMS=CSV out=work.he_data1 replace;

RUN;

 

* Calculate total fee by applying 18% Taxes;

data work.he_data1_new;

  set work.he_data1;

  TotalFee=(CourseFee*18)/100 +CourseFee ;

run;

 

* Print the SAS Data set and find the answer for first question;

PROC PRINT DATA=work.he_data1_new;

run;

 

* now apply the logic to readuce the fee by 50, if total fee is more than 500;

data work.he_data2_new;

  set work.he_data1;

  TotalFee=(CourseFee*18)/100 +CourseFee ;

  if(TotalFee>500) then TotalFee=TotalFee-50;

   MaxEndDate='31Mar2020'd;

   format MaxEndDate mmddyy8.;

run;

 

* Print the SAS Dataset and find the answer for second question;

PROC PRINT DATA=work.he_data2_new;

run;