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?
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
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
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.
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;
Thanks
It workrd fine
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.