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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Get started using SAS Studio to write, run and debug your SAS programs.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.