I am trying to make a character variable called SBPHypCat based on specifications of systolic blood pressure. So far I have this code:
data WORK.Illus;
set HypTabs.Src_Mississippi_VS;
if SBP = low - 90 then SBPHypCat = "Below Normal";
else if SBP = 90 - < 120 then SBPHypCat = "Normal";
else if SBP = 120 - < 140 then SBPHypCat = "High Normal";
else if SBP = 140 - < 160 then SBPHypCat = "Stage 1 Hypertension";
else if SBP = 160 - < 180 then SBPHypCat = "Stage 2 Hypertension";
else SBP = 180 - high then SBPHypCat = "Stage 3 Hypertension";
run;
I am getting a bunch of errors including:
You're mixing the syntax for IF/THEN statements with the syntax for creating a format. Here's how IF/THEN statements would look:
data Illus;
set HypTabs.Src_Mississippi_VS;
length SBPHypCat $ 22;
if SBP <= 0 then SBPHypCat='Bad Measurement';
else if SBP <= 90 then SBPHypCat = 'Below Normal';
else if SBP <= 120 then SPBHypCat = 'Normal';
else if SBP <= 140 then SBPHypCat = 'High Normal';
else if SBP <= 160 then SBPHypCat = 'Stage 1 Hypertension';
else if SBP <= 180 then SBPHypCat = 'Stage 2 Hypertension';
else SBPHypCat = 'Stage 3 Hypertension';
run;
You're mixing the syntax for IF/THEN statements with the syntax for creating a format. Here's how IF/THEN statements would look:
data Illus;
set HypTabs.Src_Mississippi_VS;
length SBPHypCat $ 22;
if SBP <= 0 then SBPHypCat='Bad Measurement';
else if SBP <= 90 then SBPHypCat = 'Below Normal';
else if SBP <= 120 then SPBHypCat = 'Normal';
else if SBP <= 140 then SBPHypCat = 'High Normal';
else if SBP <= 160 then SBPHypCat = 'Stage 1 Hypertension';
else if SBP <= 180 then SBPHypCat = 'Stage 2 Hypertension';
else SBPHypCat = 'Stage 3 Hypertension';
run;
That makes sense. I just worked on formats, so did not release it had different syntax. Thanks!
@marianhabesland wrote:
That makes sense. I just worked on formats, so did not release it had different syntax. Thanks!
If this is for homework, you may have been expected to use a format to do the conversion, not IF/THEN statements.
Once you have the format it would look like:
SBPHypCat = put( SBP, sbp_format.);
This is not the syntax for boolean expressions in IF statements. Here are some examples. Substitute expressions for x and y. Notice there are no dashes or low or high.
x = y
x <= y
x < y
x > y
x >= y
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.