现在的位置: 首页 > 综合 > 正文

数据的更新或修改

2018年10月24日 ⁄ 综合 ⁄ 共 1383字 ⁄ 字号 评论关闭

举例学习update语句——资料来源http://support.sas.com/resources/

/**************************************************************/
/* Create pretend data.  DSD assumes the delimiter is a comma */
/* and strips the double quotes from the values with embedded */
/* delimiters.                                                */
/*                                                            */
/* A WARNING will be issued to the log due to the duplicates  */
/* found in master.                                           */
/**************************************************************/

data one;
  infile datalines dsd;
  input artist $ song :$30.;
datalines;
Abba,"Knowing Me, Knowing You"
Abba,I am the City
Abba,Mama Mia
Beatles,Blackbird
Beatles,Chains
Beatles,"Ob-La-Di, Ob-La-Da"
;

data two;
  infile datalines dsd;
  input artist $ song :$30. new;
datalines;
Abba,Waterloo,1
Beatles,Glad All Over,1
Beatles,Hey Jude,1
Doors,People Are Strange,1
;

data new;
   update one two;
   by artist;
run;
proc print;
run;

/*
Note:
Update uses observations from the transaction data set to change the values
of the corresponding observations from the master data set.
You must use a BY statement. Data needs to be in sorted order, or indexed.

Update works with two data sets only.

Note that if the master data set contains duplicates of the BY variable,
the first observation is updated and the remaining observations are ignored.

If the transaction data set contains duplicates, all values overlay
the first match in master.

If your goal is to update all the observations in master,
consider using MERGE instead.

*/

抱歉!评论已关闭.