简体   繁体   English

使用PROC IMPORT创建SAS数据集后对其进行修改

[英]Modifying A SAS Data set after it was created using PROC IMPORT

I have a dataset like this 我有一个像这样的数据集

Obs MinNo EurNo MinLav EurLav 
1   103    15.9    92    21.9 
2    68    18.5   126    18.5 
3    79    15.9   114    22.3 

My goal is to create a data set like this from the dataset above: 我的目标是从上面的数据集中创建这样的数据集:

Obs Min    Eur     Lav 
1   103    15.9    No    
2    92    21.9    Yes     
3    68    18.5    No    
4   126    18.5    Yes
5    79    15.9    No
6   114    22.3    Yes

Basically I'm taking the 4 columns and appending them into 2 columns + a Categorical indicating which set of 2 columns they came from 基本上,我要把4列添加到2列中,然后再加上“分类”,指出它们来自哪一组2列

Here's what I have so far 这是我到目前为止的

PROC IMPORT DATAFILE='f:\data\order_effect.xls' DBMS=XLS OUT=orderEffect;
RUN;

DATA temp;
INFILE orderEffect;
INPUT minutes euros @@;
IF MOD(_N_,2)^=0 THEN lav='Yes';
ELSE lav='No';
RUN;

My question though is how I can I import an Excel sheet but then modify the SAS dataset it creates so I can shove the second two columns below the first two and add a third column based on which columns in came from? 我的问题是,如何导入Excel工作表,然后修改它创建的SAS数据集,这样我就可以将前两列的后两列推到前两列,并根据其中的列添加第三列?

I know how to do this by splitting the dataset into two datasets then appending one onto the other but with the mode function above it would be a lot faster. 我知道如何通过将数据集拆分为两个数据集,然后将一个数据集追加到另一个数据集来实现此目的,但是使用上面的mode函数,它将更快。

You were very close, but misunderstanding what PROC IMPORT does. 您非常接近,但是误解了PROC IMPORT作用。

When PROC EXPORT completes, it will have created a SAS data set named orderEffect containing SAS variables from the columns in your worksheet. PROC EXPORT完成后,它将创建一个名为orderEffect的SAS数据集, orderEffect包含工作表中各列的SAS变量。 You just need to do a little data step program to give the result you want. 您只需要执行一些数据步骤程序即可得到所需的结果。 Try this: 尝试这个:

data want;

   /* Define the SAS variables you want to keep */
   format Min 8. Eur 8.1;
   length Lav $3;
   keep Min Eur Lav;

   set orderEffect;

   Min = MinNo;
   Eur = EurNo;
   Lav = 'No';
   output;

   Min = MinLav;
   Eur = EurLav;
   Lav = 'Yes';
   output;
run;

This assumes that the PROC IMPORT step created a data set with those names. 假定PROC IMPORT步骤使用这些名称创建了一个数据集。 Run that step first to be sure and revise the program if necessary. 确保首先运行该步骤,并在必要时修改程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM