基本上,我希望format
,informat
和$22
都是format
格式的$22
变量。但是,当我运行以下代码并检查变量属性时,它指出length
为2
但informat
为$2
且data ETHNIC;
set ethnicity;
format ETHNIC $ 22.; /*the format I need, but it doesn't seem to work as I wanted*/
if ETHNIC='1' then do;
ETHNIC='Hispanic or Latino';
end;
if ETHNIC='2' then do;
ETHNIC='Not Haspanic or Latino';
end;
keep SUBJID ETHNIC;
run;
为{{1} }}
$22
如何让所有三个成为private copyTableByStatus(table: Table, status: string): Table{
// XXX: Weird, javascript can't deep copy. Object.assign() only creates
// shallow copies. There should be something like Object.clone() ...
let newTable: Table = JSON.parse(JSON.stringify(table));
newTable.checkins = JSON.parse(JSON.stringify(table.checkins.map(
checkin => {
checkin.items = JSON.parse(JSON.stringify(checkin.items.filter(
item => item.statusOItem == status
)))
return checkin;
}
)))
return newTable;
}
答案 0 :(得分:1)
由于你已经有长度为2的种族变量,所以需要这个长度。因此,您需要在set语句之前使用length或format语句覆盖该长度。
data ETHNIC;
format ETHNIC $ 22. ;
set ethnicity;
if ETHNIC='1' then do;
ETHNIC='Hispanic or Latino';
end;
if ETHNIC='2' then do;
ETHNIC='Not Haspanic or Latino';
end;
run;
答案 1 :(得分:1)
因为输入和输入的名称相同;输出字段“ETHNIC”您无法更改长度,因为编译器认为您指的是输入字段。
解决方案:
代码:
/*Creating dummy data*/
data ethnicity;
input SUBJID $ ETHNIC $;
cards;
A 1
B 1
C 2
;;;
run;
data ETHNIC;
set ethnicity (rename=(ETHNIC=ETHNIC1)); /*rename ETHNIC to ETHNIC1 to avoid conflict */
format ETHNIC $ 22.; /*the format I need, but it doesn't seem to work as I wanted*/
informat ETHNIC $ 22.; /* Define Informat here*/
length ETHNIC $ 22.; /* Define Length here*/
if ETHNIC1='1' then do;
ETHNIC='Hispanic or Latino';
end;
if ETHNIC1='2' then do;
ETHNIC='Not Haspanic or Latino';
end;
keep SUBJID ETHNIC;
run;
/*Check log for table definition*/
proc sql;
describe table ETHNIC;
quit;
输出:
日志:确认字段长度,格式,信息
create table WORK.ETHNIC( bufsize=4096 )
SUBJID char(8),
ETHNIC char(22) format=22. informat=22.
);