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.
Compare very carefully the text between the IF and THEN in lines 79 and 80.
Hint line 80 has it right.
Compare very carefully the text between the IF and THEN in lines 79 and 80.
Hint line 80 has it right.
Thanks for the help. I knew it was something stupid simple that I was overlooking.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.