全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1280 1
2016-01-04
悬赏 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的,学渣求大神指点




二维码

扫码加我 拉你入群

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

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

全部回复
2016-1-4 09:14:39
data1是字符格式的,读取的时候,应使用INPUT DATE1 $8.
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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