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
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.