BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
animesh123
Obsidian | Level 7

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;

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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:);

 

 

--
Paige Miller

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

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:);

 

 

--
Paige Miller
animesh123
Obsidian | Level 7

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

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
animesh123
Obsidian | Level 7
I am not gonna use this anywhere for now maybe at some point.
As I said earlier am just learning . I came across this question and just wanna see how to resolve it
This is purely for my learning
@PaigeMiller - Thank you very much for your support
animesh123
Obsidian | Level 7
But surely please let me know if we can resolve in a easier way
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Tom
Super User Tom
Super User

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 7 replies
  • 927 views
  • 1 like
  • 3 in conversation