DATA WANTA;
INPUT ID NAME$;
DATALINES;
1 animesh
1 mardi
1 abc
;
RUN;
PROC TRANSPOSE DATA=WANTA OUT=HAVE PREFIX=NAME ;
BY ID;
VAR NAME;
RUN;
DATA WIDE;
SET HAVE;
LENGTH COMBINED $100.;
COMBINED= CATX(',' , OF NAME);
RUN;
The answer is simple, but before I give you the answer, I would like to point out that converting this type of long data set into a wide character string with commas separating the values almost always makes subsequent processing of this data more difficult. In my opinion, doing this is a bad idea, and I request that you tell us what the big picture is ... what are you going to do next after you have data set WIDE? Please let us know, because just about any subsequent processing will be easier on the long data set WANTA.
Next, for simple debugging, please read the log. It is clearly telling you that the variable named NAME does not exist.
The fix to your problem is to add a colon, which then uses all variables whose name begins with the four letters NAME
COMBINED= CATX(',' , OF NAME:);
The answer is simple, but before I give you the answer, I would like to point out that converting this type of long data set into a wide character string with commas separating the values almost always makes subsequent processing of this data more difficult. In my opinion, doing this is a bad idea, and I request that you tell us what the big picture is ... what are you going to do next after you have data set WIDE? Please let us know, because just about any subsequent processing will be easier on the long data set WANTA.
Next, for simple debugging, please read the log. It is clearly telling you that the variable named NAME does not exist.
The fix to your problem is to add a colon, which then uses all variables whose name begins with the four letters NAME
COMBINED= CATX(',' , OF NAME:);
Hey @PaigeMiller
What I am trying to do here is below is my input data
DATA HAVE;
INPUT ID NAME$;
DATALINES;
1 Animesh
1 Mardi
1 abc
;RUN;
And the ouput data I required is :
1 Animesh Mardi ABC
No, that doesn't answer the question. I want to know what you are going to do with this data once you create it. What is the next step? A report, a table, more SAS code, what? I ask because whatever it is you are trying to do NEXT could probably be done much more easily with the original data set WANTA.
Many people here in this forum have lots of experience, they can suggest the best path forward. Often beginners start marching down the wrong path, a path that is difficult and inefficient, and they insist on going down that path. That's what you are doing, going down a difficult and inefficient path The experienced people will try to guide you to a better path, that's what I am trying to do.
@animesh123 wrote:
I am not gonna use this anywhere for now maybe at some point.
As I said earlier am just learning
But surely please let me know if we can resolve in a easier way
But since you refuse to explain what the purpose of doing this data manipulation is, we don't know what the better path is. And so you have gone down this difficult and inefficient path part of the way ... and we can't help you. You have learned to do things that are not recommended, difficult and inefficient.
You don't need to use PROC TRANSPOSE to do this as you can easily do it in a data step. So if the intermediate dataset (the "wide" dataset) is not needed then don't bother to ever create it.
data have;
input id name $;
datalines;
1 animesh
1 mardi
1 abc
;
data want;
do until(last.id);
set have;
by id;
length combined $100;
combined=catx(' ',combined,name);
end;
keep id combined;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.