BookmarkSubscribeRSS Feed
sasbasls
Calcite | Level 5

I have data something like this -

 

id1   abc

id1   def

id2   pqr

id2   rst

 

------   etc

 

 

I want to have like this in output dataset -

 

id1  abc/def

id2   pqr/rst

 

 

thanks in advance,

2 REPLIES 2
FreelanceReinh
Jade | Level 19

Try this:

data have;
input id $ text $;
cards;
id1   abc
id1   def
id2   pqr
id2   rst
;

data want;
length alltext $30; /* Please adapt the length 30 to your needs! */
do until(last.id);
  set have;
  by id;
  alltext=catx('/', alltext, text);
end;
drop text;
run;

proc print data=want;
var id alltext;
run;

If you want to have ID as the first variable in the dataset (and not only in the output), you can move the LENGTH statement after the SET statement, immediately before the assignment alltext=....

Reeza
Super User

And if you don't understand the do loop before the SET statement here's another, old fashioned method. @FreelanceReinh solution is probably more efficient.

 

data want;
set have;
by id;

length var $100.;
retain var;

if first.id then call missing(var);
var=catx('/', var, text);

if last.id then output;
run;

proc print;run;

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 1931 views
  • 1 like
  • 3 in conversation