BookmarkSubscribeRSS Feed
Niz88
Calcite | Level 5
I have 2 column, A(C.A) and B(C.B)
C.A contains duplicate for eg. 1,1,1
C.B does not contain duplicate(a,b,c)
Table eg
C.A : A
C.A : B
C.A : C
How do i make it into
C.A : C.B(A,B,C)
C.A : C.B(A,B,C)
C.A : C.B(A,B,C)

Can anybody help please. Thank u.
10 REPLIES 10
Sajid01
Meteorite | Level 14

Can you be more clear please.

Niz88
Calcite | Level 5
Can sas do this
A B to A B
1 A 1 A,B and C
1 B 1 A,B and C
1 C 1 A,B and C
2 A 2 A and B
2 B 2 A and B
Tom
Super User Tom
Super User

What is your starting dataset? Show it as a data step that recreates it.

Is it something like:

data have;
  input a b $;
cards;
1 A
1 B
1 C
2 A
2 B
;

What is your desired output dataset?  Is it something like this?

data want;
  input a b_list :$20.;
cards;
1 A,B,C
2 A,B
;

If so then try:

data want;
   length a 8 b_list $20 ;
   do until(last.a);
      set have;
      by a;
      b_list=catx(',',b_list,b);
   end;
   drop b;
run;

 

Niz88
Calcite | Level 5

i want my desire input to be like

 

nO  NAME     TO      NO    NAME
1    A               1    A,B AND C
1    B               1    A,B AND C
1    C               1    A,B AND C
2    A               2    A AND B
2    B               2    A AND B

Thanks for the reply. I am new to SAS. Normally i'll just import data and SAS will auto generate the code but i cant find a way to solve this problem. Need help from all who know how to use it.  
ballardw
Super User

@Niz88 wrote:

i want my desire input to be like

 

nO  NAME     TO      NO    NAME
1    A               1    A,B AND C
1    B               1    A,B AND C
1    C               1    A,B AND C
2    A               2    A AND B
2    B               2    A AND B

Thanks for the reply. I am new to SAS. Normally i'll just import data and SAS will auto generate the code but i cant find a way to solve this problem. Need help from all who know how to use it.  

If you are dealing with Proc Import or wizard creating the data you have an issue in that the existing NAME variable is not going to be long enough to hold 3 (or more) values.

 

Do you actually want the word AND  in the data? That adds a certain amount of complication to the possible solutions.

Niz88
Calcite | Level 5

 

 

NO  NAME     TO      NO   NAME    DATA
1    A               1    A,B,C  
1    B               1    A,B,C
1    C               1    A,B,C
2    A               2    A,B
2    B               2    A,B            

thanks ballardw for the reply. ok,then i remove the word AND.   
I tried to use the advance expression to concatenate the data together but unable to do so. Will have to try tom code. I am trying to learn how to use the code.    

 

Tom
Super User Tom
Super User

What is an "advanced expression"?

You are you using some type of point and click code generator in Enterprise Guide?

ballardw
Super User

Perhaps, borrowing from @Tom 

 

The first data step is just to build something similar to what you describe as your data.

The data set TEMP is code you would run against that data set to get the value list. Depending on the actual lengths of your values the length of the list variable may need to be much larger. This sort of thing is not normally built by point and click interfaces because it is a non-standard action and makes data that is often much harder to work with for some tasks.

Then the last step combines the two data sets.

data have;
  input a b $;
cards;
1 A
1 B
1 C
2 A
2 B
;

data temp;
   length a 8 b_list $20 ;
   do until(last.a);
      set have;
      by a;
      b_list=catx(',',b_list,b);
   end;
   drop b;
run;

data want;
   merge have
         temp
   ;
   by a;
run;

Still want to know what you expect to do with the combined values, especially when they are repeated.

ballardw
Super User

@Niz88 wrote:
Can sas do this
A B to A B
1 A 1 A,B and C
1 B 1 A,B and C
1 C 1 A,B and C
2 A 2 A and B
2 B 2 A and B

There is not way in that stuff above to tell what the starting variables are or what the value per variable might be. SAS works on variables.

ballardw
Super User

Please provide an of your existing data in the form of a data step.

And please describe what you will do with the resulting data set that can't be done with it in the current form.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 10 replies
  • 683 views
  • 2 likes
  • 4 in conversation