关于SAS中虚拟变量的问题
我正在处理一个涉及创建虚拟变量的问题,但我遇到了一个问题,即在相应的引用类别中,虚拟变量缺少值,即使数据集没有缺少值。即使我选择其中一个类别作为参考类别或变量,虚拟变量值不应该为零吗?即使我没有解释丢失的值,我也有同样的问题。我已经将我的代码、日志、输出和文本文件的内容包含在上下文中,这样我的问题就更清楚了 我对家庭作业中的以下部分有意见: 纤维肌痛是一种全身疼痛的综合征,通常由风湿病学家治疗。测量纤维肌痛对患者影响的一种方法是纤维肌痛影响问卷(FIQ)。在FIQ上,高值表示疾病影响较大(不良),低值表示疾病影响较小(良好)。我们有纤维肌痛妇女参加两种疾病自我管理课程之一或接受标准护理(对照组)的数据 本研究的数据位于BS 805网站第6课作业部分的fibre03_sum18.txt文件中。数据文件中的变量为: FIQ评分(3.1格式)在分类年龄(年)之前,在分类组(1=1级,2=2级,3=标准护理)疾病严重程度(1到6分)之后进行。自数据输入本文件以来,发现了新患者的信息和对数据的更正。新患者为对照组,FIQ=8.2,疾病严重程度=2,年龄=25岁。更正是1班的第二个科目是17岁,而不是18岁 A) 使用这些数据创建临时SAS数据集。在数据集中,创建一组为组成员身份编码的指标变量。使用PROC PRINT列出数据 我使用列输入读取文本文件,但我认为也可以使用列表输入读取?包含以下数据的文本文件名为:fibre03_sum18.txt关于SAS中虚拟变量的问题,sas,dummy-variable,Sas,Dummy Variable,我正在处理一个涉及创建虚拟变量的问题,但我遇到了一个问题,即在相应的引用类别中,虚拟变量缺少值,即使数据集没有缺少值。即使我选择其中一个类别作为参考类别或变量,虚拟变量值不应该为零吗?即使我没有解释丢失的值,我也有同样的问题。我已经将我的代码、日志、输出和文本文件的内容包含在上下文中,这样我的问题就更清楚了 我对家庭作业中的以下部分有意见: 纤维肌痛是一种全身疼痛的综合征,通常由风湿病学家治疗。测量纤维肌痛对患者影响的一种方法是纤维肌痛影响问卷(FIQ)。在FIQ上,高值表示疾病影响较大(不良)
3.1 1 6 21
1.8 1 6 18
3.3 1 5 22
2.9 1 4 15
4.3 1 3 24
4.8 1 3 22
4.9 1 2 17
6.4 1 2 18
5.7 2 5 17
6.1 2 5 25
8.5 2 3 31
7.1 2 2 17
7.7 2 1 25
9.8 2 1 22
5.1 3 4 23
7.2 3 1 15
8.3 3 1 22
6.7 3 2 20
我读取数据并使用虚拟变量创建临时数据集的代码是:
*Part A: Reading in Data and Creating a Temporary Dataset;
libname HW6 'C:\Users\jackz\Desktop\SAS';
filename HW6new 'C:\Users\jackz\Desktop\SAS\fibr03_sum18.txt';
proc format;
value grpf 1='class 1' 2='class 2' 3='standard care';
run;
data one;
infile HW6new;
input @1 FIQ 3.1 @5 grp 1. @7 disev 1. @9 age 2.;
*Creating Dummy Variables;
if grp=1 then classc1=1; else if grp=2 then classc1=0;
if grp=2 then classc2=1; else if grp=1 then classc2=0;
if grp=. then classc1=.;
if grp=. then classc2=.;
label FIQ='FIQ Score'
grp='Group'
disev='Disease Severity'
age='Age';
format grp grpf.;
run;
*Printout of Dataset one;
proc print data=one label;
run;
我的代码日志是:
NOTE: Copyright (c) 2016 by SAS Institute Inc., Cary, NC, USA.
NOTE: SAS (r) Proprietary Software 9.4 (TS1M5)
Licensed to BOSTON UNIVERSITY - SFA T&R, Site 70009029.
NOTE: This session is executing on the W32_10HOME platform.
NOTE: Updated analytical products:
SAS/STAT 14.3
SAS/ETS 14.3
SAS/OR 14.3
SAS/IML 14.3
SAS/QC 14.3
NOTE: Additional host information:
W32_10HOME WIN 10.0.16299 Workstation
NOTE: SAS initialization used:
real time 0.96 seconds
cpu time 0.95 seconds
1 *Part A: Reading in Data and Creating a Temporary Dataset;
2 libname HW6 'C:\Users\jackz\Desktop\SAS';
NOTE: Libref HW6 was successfully assigned as follows:
Engine: V9
Physical Name: C:\Users\jackz\Desktop\SAS
3 filename HW6new 'C:\Users\jackz\Desktop\SAS\fibr03_sum18.txt';
4 proc format;
5 value grpf 1='class 1' 2='class 2' 3='standard care';
NOTE: Format GRPF has been output.
6 run;
NOTE: PROCEDURE FORMAT used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
7 data one;
8 infile HW6new;
9 input @1 FIQ 3.1 @5 grp 1. @7 disev 1. @9 age 2.;
10 *Creating Dummy Variables;
11 if grp=1 then classc1=1; else if grp=2 then classc1=0;
12 if grp=2 then classc2=1; else if grp=1 then classc2=0;
13 if grp=. then classc1=.;
14 if grp=. then classc2=.;
15 label FIQ='FIQ Score'
16 grp='Group'
17 disev='Disease Severity'
18 age='Age';
19 format grp grpf.;
20 run;
NOTE: The infile HW6NEW is:
Filename=C:\Users\jackz\Desktop\SAS\fibr03_sum18.txt,
RECFM=V,LRECL=32767,File Size (bytes)=214,
Last Modified=15Jun2018:12:56:26,
Create Time=15Jun2018:12:56:26
NOTE: 18 records were read from the infile HW6NEW.
The minimum record length was 10.
The maximum record length was 10.
NOTE: The data set WORK.ONE has 18 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.03 seconds
21 *Printout of Dataset one;
22 proc print data=one label;
NOTE: Writing HTML Body file: sashtml.htm
23 run;
NOTE: There were 18 observations read from the data set WORK.ONE.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.27 seconds
cpu time 0.06 seconds
以下是输出,尽管它没有排列:
The SAS System
Obs FIQ Score Group Disease
Severity Age classc1 classc2
1 3.1 class 1 6 21 1 0
2 1.8 class 1 6 18 1 0
3 3.3 class 1 5 22 1 0
4 2.9 class 1 4 15 1 0
5 4.3 class 1 3 24 1 0
6 4.8 class 1 3 22 1 0
7 4.9 class 1 2 17 1 0
8 6.4 class 1 2 18 1 0
9 5.7 class 2 5 17 0 1
10 6.1 class 2 5 25 0 1
11 8.5 class 2 3 31 0 1
12 7.1 class 2 2 17 0 1
13 7.7 class 2 1 25 0 1
14 9.8 class 2 1 22 0 1
15 5.1 standard care 4 23 . .
16 7.2 standard care 1 15 . .
17 8.3 standard care 1 22 . .
18 6.7 standard care 2 20 . .
您可以看到,虚拟变量classc1和classc2缺少值,即使原始数据集中没有缺少值。由于组3不属于grp=1或grp=2,这些值是否应为0
如果我做错了什么,有人能给我一些关于我做错了什么的提示吗?谢谢你的帮助 输出显示标志变量缺少值的行的group=3(标准维护)。缺少的值不是由于if语句而缺少的,而是由于隐式循环开始时将数据步骤变量隐式重置为缺少 当group=3时,没有导致标志变量从初始“重置为缺失”更改的if语句
* when grp=3 neither classic1 nor classic2 variable is changed from its initial missing value;
put 'NOTE: ' _n_= (classic:) (=);
if grp=1 then classc1=1; else if grp=2 then classc1=0;
if grp=2 then classc2=1; else if grp=1 then classc2=0;
if grp=. then classc1=.;
if grp=. then classc2=.;
put 'NOTE: ' _n_= (classic:) (=);