HI All,
I have a dataset like
| STATE_CDOE | L1_NAME | L2_NAME | L3_NAME |
|---|---|---|---|
| RJ | AJMER | PATNA |
Now I want to Export this dataset in Excel like below.
| Header 1 | Header 2 |
|---|---|
| STATE_CODE | RJ |
| L1_NAME | AJMER |
| L2_NAME | PATNA |
| L3_NAME |
Can any one of you help me on this .
Thanks In advance.
You could do it with the TRANSPOSE Procedure:
PROC TRANSPOSE DATA=HAVE OUT=WANT (RENAME =(_NAME_ = 'HEADER 1'N COL1 = 'HEADER 2'N));
VAR STATE_CODE--L3_NAME;
RUN;
You could do it with a do loop as follows.
DATA WANT;
SET HAVE;
ARRAY C_VARS STATE_CODE--L3_NAME;
DO I = 1 TO HBOUND(C_VARS);
'HEADER 1'N = VNAME(C_VARS{I});
'HEADER 2'N = C_VARS{I};
OUTPUT;
END;
KEEP 'HEADER 1'N 'HEADER 2'N;
RUN;
Thnaks a lot.
Its working
You can also use the DATA | TRANSPOSE task if you want to use the EG point and click functionality.
Tom
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.