BookmarkSubscribeRSS Feed
Ossy
Calcite | Level 5

How can I create new variables, I have attached the dataset.

  1. what is the prevalence  of hypertension in the class? (Systolic >120 and Diastolic >90
  2. What is the  prevalence of high cholesterol in the class (cholesterol ≥240)?
  3. What is the prevalence of  diabetes in the class (glucose ≥126)?
  4. What  is the  prevalence of obese (BMI) ≥30,  based on height and weight in inches                 
  5. 1=Female and 2=Male
  6.  Calculate the prevalence of hypertension, diabetes, high cholesterol, and obesity by Sex
1 REPLY 1
ballardw
Super User

Since we do not have your spreadsheet file that code to Import it does not provide a data set.

 

This sounds like class work. What have you done so far?

 

A data step is typically used to perform conditional actions like adding a variable to indicate some is "true" or not in a data step. With two variable you use an IF statement that uses both variables and the boundary value to test and set the value of a new variable to indicate if the comparison is of the level of interest or not, typically numeric 1 or zero for true or false. An example:

If var1>somevalue and var2>differentvalue then newvar=1;
else newvar=0;

Comparisons might be =, < , > or GE (greater than or equal) or LE (less than or equal).

Same with single variables but only one comparison is needed.

If othervariable le 16 then anewvariable is 1;
else 0;

Or you can use syntax of Newvariable = (comparison code) as SAS will return 1 for true and 0 for false.

HighChol = (Cholesterol ge 240);

 

Were you provided a formula to calculate BMI? Calculate BMI and then the same sort of comparison.

After you have the new variables then use Proc freq with a tables that has Sex * condition.

 

Here is an example with the SASHELP.Class data set:

Proc freq data=sashelp.class;
   tables sex* age;
run;

You will get counts and percentages, overall, row and column of each level of sex compared with each level of age.

When you want to have multiple variables compared use () to group lists:

tables sex * (highchol obese hypertension diabetes);

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 426 views
  • 0 likes
  • 2 in conversation