全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
15252 5
2009-02-11

一般是下面这样的,但是有一个问题是这个format是保持在work里面的,电脑重新启动就没了,于是乎我就修改成这样PROC FORMAT library=sasuser;这样的话就保存到sasuser里面去了,但是不知道怎么调用,例如后面分析 proc print;format agefmt .(这个agefmt.前面后面加上sasuser什么的都不行)

</P> <P>PROC FORMAT; </P> <P>&nbsp;&nbsp;&nbsp;&nbsp; VALUE GENDERFMT 1='Male' 2='Female'; VALUE GENDERFMT 1='Male' 2='Female'; </P> <P>&nbsp; &nbsp;&nbsp; VALUE AGEFMT 1-25='25 and below' VALUE AGEFMT 1-25='25 and below' &nbsp; 26-30='26-30' &nbsp; 31-35='31-35' &nbsp; 36-40='36-40' </P> <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 41-45='41-45' &nbsp; 46-50='46-50' &nbsp; 51-55='51-55' &nbsp; 56-60='56-60' </P> <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; OTHER='60 and above'; OTHER='60 and above'; </P> <P>&nbsp;&nbsp; VALUE DEGREEFMT 1='BA' VALUE DEGREEFMT 1='BA' &nbsp; 2='Working on MB' 2='Working on MB' &nbsp; 3='Oversea MB' &nbsp; 4='Local MB' 4='Local MB' </P> <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5='Working on PH.D' 5='Working on PH.D' &nbsp; 6='Oversea PH.D' 6='Oversea PH.D' &nbsp; 7='Local PH.D' &nbsp; 8='Otherwise'; </P> <P>&nbsp;&nbsp; VALUE EXPFMT 0-5='0-5' VALUE EXPFMT 0-5='0-5' &nbsp; 6-10='6-10' &nbsp; 11-15='11-15' &nbsp; 16-20='16-20' </P> <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 21-25='21-25' &nbsp; 26-30='26-30' &nbsp; 31-35='31-35'; </P> <P>&nbsp; &nbsp;&nbsp;&nbsp; VALUE FREQFMT VALUE FREQFMT &nbsp; 0='0' &nbsp; 1-2='1-2' &nbsp; 3-4='3-4' &nbsp; 5-6='5-6' &nbsp; 7-8='7-8'; </P> <P>DATA A1; </P> <P>&nbsp; INFILE 'CONTEST.TXT'; INFILE 'CONTEST.TXT'; </P> <P>&nbsp; INPUT OBS GENDER AGE DEGREE EXP FREQ; INPUT OBS GENDER AGE DEGREE EXP FREQ; </P> <P>PROC PRINT; </P> <P>&nbsp; FORMAT GENDER GENDERFMT. FORMAT GENDER GENDERFMT. </P> <P>AGE AGEFMT. AGE AGEFMT. </P> <P>DEGREE DEGREEFMT. DEGREE DEGREEFMT. </P> <P>EXP EXPFMT. EXP EXPFMT. </P> <P>FREQ FREQFMT.; FREQ FREQFMT.; </P> <P>RUN; </P> <P>

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2009-2-11 12:59:00

you need to add a SAS system option before using the format. Here is an example from the book 'The Power of Proc Format'. you can try it.

proc format library=library.fmtest;
         value $sx 'M' = 'MALE'
                   'F' = 'FEMALE'
                 other = 'OTHER'
;
run;

/* However, when you want to use the $SX format stored in library.fmtest you will need to use the FMTSEARCH option as follows: */


options fmtsearch=(work library.fmtest);

In addition, your proc format have some repeated parts. You need to remove these:

VALUE GENDERFMT 1='Male' 2='Female';
VALUE AGEFMT 1-25  = '25 and below'
OTHER = '60 and above';
VALUE EXPFMT   0-5 ='0-5'
VALUE FREQFMT

[此贴子已经被作者于2009-2-11 13:55:54编辑过]

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2009-3-2 09:00:00
以下是引用yongyitian在2009-2-11 12:59:00的发言:

you need to add a SAS system option before using the format. Here is an example from the book 'The Power of Proc Format'. you can try it.

proc format library=library.fmtest;
         value $sx 'M' = 'MALE'
                   'F' = 'FEMALE'
                 other = 'OTHER'
;
run;

/* However, when you want to use the $SX format stored in library.fmtest you will need to use the FMTSEARCH option as follows: */


options fmtsearch=(work library.fmtest);

In addition, your proc format have some repeated parts. You need to remove these:

VALUE GENDERFMT 1='Male' 2='Female';
VALUE AGEFMT 1-25  = '25 and below'
OTHER = '60 and above';
VALUE EXPFMT   0-5 ='0-5'
VALUE FREQFMT


3Q I got it
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-8-15 10:34:59
yongyitian 发表于 2009-2-11 12:59
you need to add a SAS system option before using the format. Here is an example from the book 'The P ...
能解释一下value和invalue,put 和input的区别吗? 总是把这个搞的很混乱。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-9-18 22:13:40
ilovekate 发表于 2014-8-15 10:34
能解释一下value和invalue,put 和input的区别吗? 总是把这个搞的很混乱。
不好意思,回复的有点晚了,input和put确实很容易弄混。 看下面的解释是否有帮助。

1. invalue 和value 只在proc format中使用。在 proc format 中
   invalue 用来定义输入格式 (informat) 
     value 用来定义输出格式 ( format )。

2. input 是输入语句,即把数据读入到数据集里的语句,所以在input语句中要用输入格式(informat).
     put 是输出语句,是把数据集里的数据输出到log里,或者写到外部文件中, 所以在put语句中要用输出格式(format).

3. 数据步中,只有用informat和format语句定义的输入,输出格式才会被储存在数据集中。
   没有用informat和format定义而只在 input 语句中用到的格式是不会被存在数据集中的。

4.  input   和 put 语句还可以在数据步(data step)中做变量类型的转换.
    input 语句:  将字符型变量转成数值型变量 (character to numeric  ).
      put 语句: 将数值型变量转成字符型变量 (  numeric to character).
   这一点很容易弄混。 

也许看一下我们是怎么做一道简单的算术题会有帮助.

例如在网上登陆和下载时可能会被要求输入一个验证码或计算一道简单的算术题,比如你要回答3+4=?

在做这道题的时候,我们通过眼睛把倆个数字传送进大脑,在大脑中算出结果,然后把结果从大脑通过手输出到键盘或纸上。

在这个过程中,眼睛看到的实际上是倆个图形/符号,或者称为字符。
而进入大脑并参加运算的是两个数字,因为在大脑中我们并没有把两个数字的形状做任何方式迭加。这个过程就是input的过程, 即把字符型变量转成数值型便量的输入过程.  

input 可以看成是两个字 in 和 put,in就是里面或进来的意思。

相反, 把在大脑中计算好的数字结果作为一个数字符号写在纸上或显示在计算机频幕上,就是一个put过程.
即把数字型变量转成字符型便量的输出过程.

而眼睛看到的字符之所以会在大脑中被转化成数字是因为我们通过大量的学习和训练已经把数字的形状做为一种格式牢牢的存在了大脑中. 所以当眼睛把看到的字符输送到大脑后,就会被自动的转化为数字.

当搞不清到底是用 input 还是用 put 时,想一想这个例子可能会有帮助。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-9-19 11:06:39
yongyitian 发表于 2014-9-18 22:13
不好意思,回复的有点晚了,input和put确实很容易弄混。 看下面的解释是否有帮助。

1. invalue 和val ...
很有用,谢谢!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群