BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
shru
Calcite | Level 5

Hi,

the data is,

shri

bengal

india

shety

Ka

India

and i want o/p as

name   state   country

shri     bengal   india

shety  Ka        india

How can i achieve this?

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

If your data always lays like this, and there is no missing rows, switching rows etc, you can try this array approach:

data have;

input var $20.;

cards;

shri

bengal

india

shety

Ka

India

;

data want (drop=var);

array v $ name state country;

do _n_=1 to 3;

set have;

v(_n_)=var;

end;

run;

proc print;run;

Regards,

Haikuo

View solution in original post

4 REPLIES 4
Haikuo
Onyx | Level 15

If your data always lays like this, and there is no missing rows, switching rows etc, you can try this array approach:

data have;

input var $20.;

cards;

shri

bengal

india

shety

Ka

India

;

data want (drop=var);

array v $ name state country;

do _n_=1 to 3;

set have;

v(_n_)=var;

end;

run;

proc print;run;

Regards,

Haikuo

Astounding
PROC Star

Or simply:

data want;

length name country state $ 20;

input name & country & state &;

cards;

shri

bengal

india

shety

Ka

India

;

The &s just allow an embedded blank to be part of the variable.  They are not necessary when you have no embedded blanks.

Good luck.

ballardw
Super User

Or

data want;

length name country state $ 20;

infile <your input filename or ref>;

input #1 name #2 country #3 state;

input; /* to skip blank line  assuming the pattern is consistent*/

run;

shru
Calcite | Level 5

Thanks

It workrd fine

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 981 views
  • 3 likes
  • 4 in conversation