본문 바로가기

SAS/Scenario

Scenario 5

 

 

Open the ehs01 program from the EHS folder and correct the errors in the program.

For instructions, see the commented code in the program that is marked by a slash(/) and an asterisk(*).

 

 

Example Code1   ehs01 Program : Fix the Errors

 

data work.aprilbills drop=Total, EquipCost;

   set cort.aprbills;

   if Days > 7 then Discount=(RoomCharge) * 20% else 0;

   TotalDue=Total - Discount;

   format DateIn DateOut date9;

   format RoomRate RoomCharge Discount TotalDue dollar10.;

proc print data=work.aprilbills.

 

잘못된 코드 (보기)

 

 

Here are instructions that are commented in the program, ehs01.

  • Drop the variables Total and EquipCost.
  • If the Days variable is greater than 7, then Discount is the value of RoomCharge multiplied by 20 %. If the Days variable is less than or equal to 7, then Discount is set to 0.
  • Create a new variable, TotalDue, with a value of Total minus Discount.
  • Format DateIn and DateOut to appear as 05APR2009.
  • Format the variables RoomRate, RoomCharge, Discount, and TotalDue to appear as $100.00.
  • Print your results.

 

 

[사용 코드]

 

libname cert 'C:/folders/mypath/cert/';
data work.aprilbills (drop=total equipcost);
     set cert.aprbills;
     if days > 7 then discount=(roomcharge)*0.2; else discount=0;
     totaldue = total-discount;
     format datein dateout date9.;
     format roomrate roomcharge discount totaldue dollar10.2;
 run;


proc print data=work.aprilbills;
run; 

 

  • DROP = data set option 은 ( ) 안에서 사용 !!
  • datew. / dollarw.d 사용법 정확히 파악하기 !!

 

 

 

Work.Aprilbills

 

 

 

DOLLARw.d Format

출처 : https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/p03sgbuduqemljn1nqj7qm1leql9.htm

 

 

 

 

DATEw. Format

출처 : https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/n16vcb736tge20n1ex3yxx49fzqa.htm

'SAS > Scenario' 카테고리의 다른 글

Scenario 7  (0) 2022.12.25
Scenario 6  (0) 2022.12.25
Scenario 4  (0) 2022.12.25
Scenario 3  (0) 2022.12.25
Scenario 2  (0) 2022.12.25