BookmarkSubscribeRSS Feed
nandanosho
Obsidian | Level 7

HI All,

I have a dataset like

STATE_CDOEL1_NAMEL2_NAMEL3_NAME
RJAJMERPATNA

Now I want to Export this dataset in Excel like below.

Header 1Header 2
STATE_CODERJ
L1_NAMEAJMER
L2_NAMEPATNA
L3_NAME

Can any one of you help me on this .

Thanks In advance.

3 REPLIES 3
Scott_Mitchell
Quartz | Level 8

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;

nandanosho
Obsidian | Level 7

Thnaks a lot.

Its working

TomKari
Onyx | Level 15

You can also use the DATA | TRANSPOSE task if you want to use the EG point and click functionality.

Tom

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 809 views
  • 0 likes
  • 3 in conversation