Elif Y
Elif Y

Reputation: 251

Simplifying the variable input in SAS

I have 90 variables in the data, I want to do the following in SAS.

Here is my SAS code:

data test;
  length id class sex $ 30;
  input id $ 1 class $ 4-6 sex $ 8 survial $ 10;
cards;
1  3rd F Y
2  2nd F Y
3  2nd F N
4  1st M N
5  3rd F N
6  2nd M Y
;
run;
data items2;
set test;
length tid 8;
length item $8;
tid = _n_;
item = class;
output;
item = sex;
output;
item = survial;
output;
keep tid item;
run;

What if I have 90 variables to input the data like this? There should be a very long list. I want to simplify it.

Upvotes: 0

Views: 79

Answers (2)

user2337871
user2337871

Reputation: 462

I don't seem to be able to add another comment to the above answer, as such I am adding one here.

You need to extend the VAR statement to include all variables that you want transposed.

CLASS -- SURVIAL means all variables between CLASS and SURVIVAL inclusive.

Post your code and the error so that I can help you better.

Upvotes: 0

user2337871
user2337871

Reputation: 462

You could use an ARRAY or alternately a PROC TRANSPOSE.

The following is untested, because you haven't provided an exxample of your input dataset.

DATA ITEMS;
ARRAY VARS {*} VAR1-VAR90;
SET REPLACE;
DO I = LBOUND(VARS) TO HBOUUND(VARS);
    ITEM = VARS{I};
    OUTPUT;
END;
RUN;

OR

PROC TRANSPOSE DATA = TEST OUT = WANT;
    BY ID;
    VAR CLASS -- SURVIAL;
RUN;

In the future it would be best is you could supply your input and desired output.

Upvotes: 1

Related Questions