Chris
Chris

Reputation: 65

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

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?

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.

Upvotes: 1

Views: 1061

Answers (1)

BellevueBob
BellevueBob

Reputation: 9618

You were very close, but misunderstanding what PROC IMPORT does.

When PROC EXPORT completes, it will have created a SAS data set named orderEffect containing SAS variables from the columns in your worksheet. 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. Run that step first to be sure and revise the program if necessary.

Upvotes: 1

Related Questions