楼主: sanyecao
1093 1

求指点char,num转化的题目[sas programming by example] [推广有奖]

  • 0关注
  • 0粉丝

高中生

22%

还不是VIP/贵宾

-

威望
0
论坛币
249 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
68 点
帖子
9
精华
0
在线时间
36 小时
注册时间
2005-5-1
最后登录
2020-3-1

5论坛币
题目:是[sas programming by example]的problem5-5
You have two SAS data sets, ONE and TWO. Data set ONE contains a variable called DATE1 which is a character variable in the form MM/DD/YY. (i.e. variable DATE1 is not a SAS date, which is a numerical quantity, but rather a character string of length 8.) Variables HEIGHT and WEIGHT are also contained in data set ONE. Data set TWO contains a character variable called DATE2 which is in the form ddMONyy. Data set TWO also contains the variable HR (heart rate). Write a program to merge these data sets by date, and assume that there are no duplicate dates in each of the data sets. Solve this problem two ways:


a) Use the PUT function to create a new variable in one of the data sets so that the two data sets have an identical variable to use.


我写的code:


/*5-5*/
DATA ONE;
        INPUT DATE1 $ 8. HEIGHT WEIGHT;
DATALINES;
10/21/46 58 155
09/05/55 66 220
01/11/44 63 205
;
RUN;

DATA TWO;
        INPUT DATE2: $7. HR;
DATALINES;
210CT46 58
11JAN44 68
05SEP55 72
;
RUN;

DATA NEWTWO;
        SET TWO;
        DATE1 = PUT (INPUT(DATE2, DATE7.),MMDDYY8.);
        DROP DATE2;
RUN;

PROC SORT DATA=ONE;
         BY DATE1;
RUN;

PROC SORT DATA=NEWTWO;
       BY DATE1;

RUN;

DATA BOTH;
        MERGE ONE NEWTWO;
        BY DATE1;
RUN;

PROC PRINT DATA=BOTH;
TITLE'MERGE';
RUN;

我从put,input那一步的结果 date就是missing的,学渣求大神指点




关键词:Programming example Program ExamP Exam character quantity example called
data1是字符格式的,读取的时候,应使用INPUT DATE1 $8.

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-25 08:10