一、日期变量与财务数据变量
- 不设置输出格式
data bank2;
input @1 no $3.
@4 time mmddyy10.
@14 gender $1.
@15 money 7.;
datalines;
00110/21/1955M 1145
00211/18/2001F 18722
00305/07/1944M 123.45
00401/01/1960F -12345
;
title'bank of new information';
/*没有对日期的输出格式进行设置,就会显示具体离1960年1月1日的天数*/
proc print data=bank2 noobs;
run;
- 设置输出格式
data bank2;
input @1 no $3.
@4 time mmddyy10.
@14 gender $1.
@15 money 7.;
datalines;
00110/21/1955M 1145
00211/18/2001F 18722
00305/07/1944M 123.45
00401/01/1960F -12345
;
title'bank of new information';
/*修改日期的输出格式,财务数据加上美元符号或者逗号*/
proc print data=bank2 noobs;
/*mmddyy10.也可以改成date9.*/
format time mmddyy10.
money dollar11.2;
run;
- 输出结果
不设置输出格式
设置输出格式
二、列输入方式、添加label、用户自定义的format
- 问题的来源
来自经管之家的提问:怎样批量输入有格式的变量?
链接:添加链接描述
2. 无label和format
data suvey;
input subj:$3.
gender: $1.
age:2.
salary:6.
(ques1-ques5)($1. +1);
cards;
001 M 23 28000 1 2 1 2 3
002 F 55 76123 4 5 2 1 1
003 M 38 36500 2 2 2 2 1
004 F 67 128000 5 3 2 2 4
;
run;
proc print data=suvey noobs;
format salary dollar11.2;
run;
- 添加label和自定义format
data suvey;
input subj:$3.
gender: $1.
age:2.
salary:6.
(ques1-ques5)($1. +1);
label subj='工号'
gender='性别'
age='年龄'
salary='薪水'
Ques1='The governor is doing a good job?'
Ques2='The property tax should be lowered'
Ques3='Guns should be banned'
Ques4='Expand the Green Acre program'
Ques5='The school needs to be expanded';
cards;
001 M 23 28000 1 2 1 2 3
002 F 55 76123 4 5 2 1 1
003 M 38 36500 2 2 2 2 1
004 F 67 128000 5 3 2 2 4
;
run;
proc format;
value $ gender
'M'='Male'
'F'='Female'
' '='Not entered';
value age
low-29='Less than 30'
30-50='30 to 50'
51-high='51+';
value $likert '1'='Strongly disagree'
'2'='Disagree'
'3'='No opinion'
'4'='Agree'
'5'='Strongly agree';
proc print data=suvey ;
*若想要输出变量的标签信息,可以写成括号里面的信息(proc print data=suvey label;);
id subj;
var gender age salary Ques1-Ques5;
format Gender $gender.
Age age.
Ques1-Ques5 $likert.
Salary dollar11.2;
run;
- 运行结果
无label和format的结果
添加label和自定义format(不输出label)
添加label和自定义format(输出label)
解读代码中一些语句
第一个:符号@
符号@称为列指针(Column Pointer),@4就是告诉SAS,指到第4列。
第二个:用户自定义format的格式
PROC FORMAT;
VALUE format-name
Data-value-1 = ‘Label 1’
Data-value-2 = ‘Label 2’;
VALUE format-name-2
Data-value-3 = ‘Label 3’
Data-value-4 = ‘Label 4’;
…;
RUN;
备注:来自添加链接描述
感谢和参考
官网添加链接描述
书籍《Learning_SAS_by_Example,_A_Programmers_Guide》
其他
如有冒犯您的信息,请联系作者qq:359678664删除文章。