我正在尝试探索是否可以使用proc sql
而不是proc format
创建用户定义的格式?它是否可以实现。我们可以使用proc sql
编辑格式目录吗?我试图查询它,但我不能。有谁知道这是否可以实现?
谢谢!
答案 0 :(得分:2)
不,我认为proc format
是您创建格式的唯一选择,对于编辑目录文件,您只能使用proc catalog
。
答案 1 :(得分:2)
我认为用户user667489是正确的...但是有一个解决方法,这可能是有用的。
您可以通过应用case
- 逻辑:
proc sql outobs=30;
select case
when 10 <= vehicle_type or vehicle_type < 20 then 'passenger'
when 20 < vehicle_type or vehicle_type < 30 then 'lcv'
end as type
from begin;
quit;
了解详情
修改强>
让我们看看我是否可以找到更好的例子。为了论证,我定义我们对便宜的spotrscars / SUVS感兴趣并且想要创建分类变量以检测这些的任何组合。
proc sql outobs=30;
create table results as
select type
,case when type in('SUV' 'Sports') then 1
else 0
end as wanted_type
,MSRP
,case when MSRP < 30000 then 'cheap'
when MSRP > 45000 then 'Expensive'
else 'inconclusive'
end as price_range
from sashelp.cars;
quit;
此时我们有原始数据和新的分组变量想要的类型和价格范围,如下所示。当然,您不必选择原始值,但在此示例中,它是显示结果和原始值。
Type wanted_type MSRP price_range
SUV 1 $36,945 inconclusive
Sedan 0 $23,820 cheap
Sedan 0 $26,990 cheap
Sedan 0 $33,195 inconclusive
Sedan 0 $43,755 inconclusive
Sedan 0 $46,100 Expensive
Sports 1 $89,765 Expensive
Sedan 0 $25,940 cheap