You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在SAS中将医疗CSV数据集的三分类Readmitted变量转为二分类?

Recoding Readmitted to Binary for Logistic Regression in SAS

No problem at all—here are two clean, reliable ways to recode your Readmitted categorical variable into a binary (0/1) format for logistic regression in SAS:

Method 1: Create a New Binary Variable (DATA Step)

This approach makes a permanent new variable in your dataset, which is great if you'll use it across multiple analyses. Just adjust the dataset name (your_dataset) to match your actual data:

data cleaned_data;
    set your_dataset;
    /* Create binary variable: 0 = No readmission, 1 = any readmission */
    if Readmitted = "No" then Readmit_bin = 0;
    else if Readmitted in (">30", "<30") then Readmit_bin = 1;
    /* Optional: Handle missing values if needed */
    else Readmit_bin = .; /* Assign missing for any unexpected values */
run;

Method 2: Use a Custom Format (No New Variable)

If you don't want to add a new variable, you can define a format that maps the original values to 0/1 on the fly. This works well for one-off analyses or preserving the original variable:

/* Define the custom format */
proc format;
    value readmit_bin_fmt
        "No" = 0
        ">30", "<30" = 1
        other = .; /* Map invalid values to missing */
run;

/* Apply the format in your logistic regression (or any procedure) */
proc logistic data=your_dataset;
    class Readmitted / param=ref; /* Optional, but useful for reference coding */
    model Readmitted = your_predictors / link=logit;
    format Readmitted readmit_bin_fmt.; /* Apply the binary format */
run;

Quick Notes:

  • Make sure the quotes around Readmitted values match the actual data type—if Readmitted is numeric instead of character, remove the quotes (e.g., if Readmitted = 0 then ... assuming "No" was coded as 0 originally).
  • The other = . clause is optional but recommended to catch any unexpected values (like typos) and flag them as missing, which keeps your analysis clean.

内容的提问来源于stack exchange,提问作者Justin Arnold

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 06:55:57