SAS: rearrange field order in data step

后端 未结 4 1942
陌清茗
陌清茗 2021-01-05 01:22

In SAS 9, how can I in a simple data step, rearrange the order the field.

Data set2;
  /*Something probably goes here*/
  set set1;
run;

So

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-05 02:04

    If you have a very large number of variables in your dataset sometimes it is easier to use an sql statement instead of a datastep. This allows you to list just the variables whose order you care about and use a wildcard to retain everything else.

    proc sql noprint;
      create table set2 as
      select title, salary, *
      from set1;
    quit;
    

    If you are doing this with a large table you can save yourself the IO overhead by creating a view instead. This can be applied to both the data set approach or the proc sql approach.

    proc sql noprint;
      create view set2 as
      select title, *
      from set1;
    quit;
    
    ** OR;
    
    data set2 / view=set2;
      retain title salary name;
      set set1;
    run;
    

    Cheers Rob

提交回复
热议问题