BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
danalukowski228
Calcite | Level 5

For reference I am using sample code from the certification prep guide. I am using SAS Studio. The scenario is as follows, 

This scenario uses the Excel file heart.xlsx. Write a SAS program to do the following and store the results in the data set Work.Heart.

• Import the Excel file heart.xlsx.

• Drop the AgeAtDeath and DeathCause variables from the Work.Heart data set.

• Include only the observations where Status=Alive in the Work.Heart data set.

• If the AgeCHDdiag variable has a missing value (.), then do not include the value in Work.Heart.

• Create a new variable Smoking_Status, set its length to 17 characters, and use the following criteria:

     • If the value of Smoking is between 0 and less than 6, then Smoking_Status is "None (0–5)".

     • If the value of Smoking is between 6 and 15 inclusively, then Smoking_Status is "Moderate (6–15)".
     • If the value of Smoking is between 16 and 25 inclusively, then Smoking_Status is "Heavy (16–25)".

     • If the value of Smoking is greater than 25, then Smoking_Status is "Very Heavy (>25)".

     • If there are any other values for the variable Smoking, set Smoking_Status to "Error".

• Create a two-way frequency table using variables AgeCHDdiag and Smoking_Status and suppress column percentage, row percentage, and cell percentage.

Based on the scenario above, I have created the following code: 

libname practice xlsx '/home/u37611728/PracticeData/heart.xlsx';
 
data work.heart;
	set practice.heart;
	drop ageatdeath deathcause;
	where status='Alive';
	if AgeCHDdiag='.' then delete;
	length Smoking_Status $ 17;
	if <=0 smoking <6 then Smoking_Status='Non-Smoker(0-5)';
		else if 6<= smoking <=15 then Smoking_Status='Moderate (6-15)';
		else if 16<= smoking <=25 then Smoking_Status='Heavy (16-25)';
		else if smoking >25 then Smoking_Status='Very Heavy (>25)';
		else Smoking_Status='Error';
run;

proc freq data=work.heart;
	tables AgeCHDdiag*Smoking_Status / nocol norow nopercent;
run;

I checked the answer key in the book and it is the same answer. I am getting the following errors. Any help will be greatly appreciated. 🙂

 79         if <=0 smoking <6 then Smoking_Status='Non-Smoker(0-5)';
                __
                386
                200
                76
 80         else if 6<= smoking <=15 then Smoking_Status='Moderate (6-15)';
              ____
              160
 ERROR 386-185: Expecting an arithmetic expression.
 
 ERROR 200-322: The symbol is not recognized and will be ignored.
 
 ERROR 76-322: Syntax error, statement will be ignored.
 
 ERROR 160-185: No matching IF-THEN clause.
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Compare very carefully the text between the IF and THEN in lines 79 and 80.

Hint line 80 has it right.

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Compare very carefully the text between the IF and THEN in lines 79 and 80.

Hint line 80 has it right.

danalukowski228
Calcite | Level 5

Thanks for the help. I knew it was something stupid simple that I was overlooking.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

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
  • 2 replies
  • 643 views
  • 0 likes
  • 2 in conversation