BookmarkSubscribeRSS Feed
CPoston
Obsidian | Level 7

I have a question about scenario 2.  

 

The directions state to remove observations with RestHR values >= 70 and to remove TotalTime values < 600.  

 

Here is my code:

 

data stress1 ;
	set cert.stress ;
	if RestHR >= 70 then delete ; 
	TotalTime=(TimeMin*60) + TimeSec ;
	if TotalTime < 600 then delete ;
run ;

proc print data=stress1 ;
run ;

My answers are:

 

1. 4 observations

2. 1055

 

The answers in the prep guide are:

 

1. 5

2. 1055

 

I don't understand why the where clause is used.  The answer code says to use a where statement to determine the RestHR values.  Ex:  where RestHR <= 70.  This doesn't make sense to me because the instructions state to remove values >=70 for RestHR and remove values for TotalTime < 600.  

 

Attached are the instructions.

7 REPLIES 7
sabisw
SAS Employee

@CPoston Hey there!

 

Not sure if you had a chance yet to do so or not, but check out the Content Updates page. 

 

The best practice is to use the WHERE statement. WHERE statement works on variables in the data set that we are reading and is a preprocessor. You can use the IF-THEN statement for the second part where you are removing values for TotalTime that are less than 600 because you are creating the variable TotalTime in the step above.

 

Thanks,

Samantha

CPoston
Obsidian | Level 7

@sabisw 

 

Thanks for the explanation!

 

As I was working through the scenario's, another question came up.  I think I have the wrong data for Scenario 6.  Attached is the proc contents for the heart.xlsx file I have.  I will attach the log that generated from my code and the log with the SAS code in the answer section in a separate post since it only lets me attach one at a time.  There is no variable AgeAtDeath and the Smoking_Status variable is already created. Please advise.  Thanks!  

 

SAS log:

 

1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 72         
 73         libname certdata xlsx '/folders/myfolders/Prep Guide Data/base-guide-practice-data/cert/heart.xlsx' ;
 NOTE: Libref CERTDATA was successfully assigned as follows: 
       Engine:        XLSX 
       Physical Name: /folders/myfolders/Prep Guide Data/base-guide-practice-data/cert/heart.xlsx
 74         data work.heart ;
 75         set certdata.heart (drop=AgeAtDeath DeathCause) ;
 ERROR: The variable AgeAtDeath in the DROP, KEEP, or RENAME list has never been referenced.
 76         where Status='Alive' ;
 77         if AgeCHDdiag=. then delete ;
 78         length Smoking_Status $17 ;
 79         if 0<=Smoking<6 then Smoking_Status = 'Non-Smoker(0-5)' ;
 80         else if 6<=Smoking<=15 then Smoking_Status='Moderate (6-15)' ;
 81         else if 16<=Smoking<=25 then Smoking_Status='Heavy (16-25)' ;
 82         else if Smoking>25 then Smoking_Status='Very Heavy (>25)' ;
 83         else Smoking_Status='Error' ;
 84         run ;
 
 NOTE: The SAS System stopped processing this step because of errors.
 WARNING: The data set WORK.HEART may be incomplete.  When this step was stopped there were 0 observations and 3 variables.
 WARNING: Data set WORK.HEART was not replaced because this step was stopped.
 NOTE: DATA statement used (Total process time):
       real time           0.79 seconds
       cpu time            0.76 seconds
       
 
 85         
 86         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 98         

My log:

 

 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 72         
 73         data heart2 ;
 74         set heart (drop=AgeAtDeath DeathCause) ;
 ERROR: The variable AgeAtDeath in the DROP, KEEP, or RENAME list has never been referenced.
 75         length Smoking_Status $17 ;
 76         where Status='Alive' ;
 77         if AgeCHDdiag=. then delete ;
 78         if Smoking >0 and <6 then Smoking_Status='None (0-5)' ;
                               _       _______________
                               22      180           180
 79         else if Smoking >=6 and <= 15 then Smoking_Status='Moderate (6-15)' ;
                                     __         _______________
                                     22         180           180
 80         else if Smoking >=16 and <=25 then Smoking_Status='Heavy (16-25)' ;
                                      __        _______________
                                      22        180           180
 ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, 
               a missing value, INPUT, PUT.  
 
 ERROR 180-322: Statement is not valid or it is used out of proper order.
 
 81         else if Smoking >25 then Smoking_Status='Very Heavy (>25)' ;
 82         else Smoking_Status = 'Error' ;
 83         run ;
 
 NOTE: The SAS System stopped processing this step because of errors.
 WARNING: The data set WORK.HEART2 may be incomplete.  When this step was stopped there were 0 observations and 3 variables.
 WARNING: Data set WORK.HEART2 was not replaced because this step was stopped.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       cpu time            0.01 seconds
       
 
 84         
 85         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 97         
CPoston
Obsidian | Level 7

@sabisw SAS Log

CPoston
Obsidian | Level 7

@sabisw my log

ballardw
Super User

It is better to post LOG or Code in a code box opened using the Forum's {I} or "running man" icons. Copy from the log and in the forum click on the icon, paste into the code box.

Much simpler than creating a separate file and attaching. Plus the messages can be seen in line and it is easier for others to copy and paste or highlight stuff.

 

Example (though this got reformatted because of Copy from a PDF)

73 libname certdata xlsx '/folders/myfolders/Prep Guide Data/base-guide-practice-data/cert/heart.xlsx' ;
NOTE: Libref CERTDATA was successfully assigned as follows:
Engine: XLSX
Physical Name: /folders/myfolders/Prep Guide Data/base-guide-practice-data/cert/heart.xlsx
74 data work.heart ;
75 set certdata.heart (drop=AgeAtDeath DeathCause) ;
ERROR: The variable AgeAtDeath in the DROP, KEEP, or RENAME list has never been referenced.
76 where Status='Alive' ;
77 if AgeCHDdiag=. then delete ;
78 length Smoking_Status $17 ;
79 if 0<=Smoking<6 then Smoking_Status = 'Non-Smoker(0-5)' ;
80 else if 6<=Smoking<=15 then Smoking_Status='Moderate (6-15)' ;
81 else if 16<=Smoking<=25 then Smoking_Status='Heavy (16-25)' ;
82 else if Smoking>25 then Smoking_Status='Very Heavy (>25)' ;
83 else Smoking_Status='Error' ;
84 run ;
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.HEART may be incomplete. When this step was stopped there were 0 observations and 3 variables.
WARNING: Data set WORK.HEART was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.79 seconds
cpu time 0.76 seconds

Some thing to check: Does the XLSX file have a column heading "AgeAtDeath" or did someone manage to create one like "Age At Death"?

 

 

And again, the link shown by @sabisw should be checked.

CPoston
Obsidian | Level 7

Thanks @ballardw , I'll update.  I thought you could only put code in there.  The xlsx file does not have a column called Age At Death and there aren't any instructions to create it.  I checked the errata in the link from @sabisw and there is no mention about the heart.xlsx file for scenario 6.

sabisw
SAS Employee

@CPoston, I'm attaching the correct Excel file for you to use. I apologize, our sample data has created the Certdata.Heart instead of the Excel file.

 

 

Welcome to the Certification Community

 

This is a knowledge-sharing community for SAS Certified Professionals and anyone who wants to learn more about becoming SAS Certified. Ask questions and get answers fast. Share with others who are interested in certification and who are studying for certifications.To get the most from your community experience, use these getting-started resources:

Community Do's and Don'ts
How to add SAS syntax to your post
How to get fast, helpful answers

 

Why Get SAS Certified.jpg

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 2657 views
  • 2 likes
  • 3 in conversation