sas >> how to combine two columns into one column

by Jinto83 » Wed, 13 May 2009 12:06:39 GMT

Hi,

I have a dataset that has a column "Address 1" and "Address 2", how do I combined them (with an space character seperating between the two)into a single column "Address" . Thanks.

sas >> how to combine two columns into one column

by pinu » Wed, 13 May 2009 14:36:18 GMT



Hi Jinto,
The following code will solve your problem.
data one;
infile cards;
input Addr1 $ Addr2 $;
datalines;
abc xyz
asd jkl
axa sil
;

data two;
set one;
length Address $ 10; *Specify sufficient lenght to hold the
concatenated data;
Address = trim(left(Addr1)) || ' ' || trim(left(Addr2));
run;
proc print data = two;
run;

Regards,
Amar Mundankar.

sas >> how to combine two columns into one column

by inason » Wed, 13 May 2009 18:24:35 GMT


You may also wish to use the catx function, which does exactly as Amar
wrote but is simple.

address=catx(' ',addr1, addr2);

Ibrahim

Similar Threads

1. Combine 2 dataset column by column into one dateset then ODS

2. Combine 2 dataset column by column into one dateset then ODS to

Hi,

Suppose I have 2 dataset (A and B)  with similar data structure except
variable name different by _A or _B.

Data A : V1_A --V50_A

Data B: V1_B-- V50_B

In Data A, it hold the schdule date  V1_A to V50_A.
In Data B, it hold the actual date  V1_B to V50_B correspond to V1_A to
V50_A. (But some actual date date could be empty).

How Can I combine the 2 dataset as follow and ODS to EXCEL as follow:

1)   V1_A  V1_B   V2_A  V2_B  -------- V50_ A V50_B  as one dataset.

2)  ODS  Excel, if  VX_B has empty date then  VX_A cell should shaded with
"Yellow".

Appreicate your help on this.

Randy

3. Best way to combine 2 columns of data into 1 column

4. Best way to combine 2 columns of data into 1 column

How about ...

proc sql;
create table new as
select Q8 as new_column
from old
union
select Q9
from old;
quit;


Mark Biek wrote:

> Ed-
>         Q8 and Q9 are both strings.
>
> Let's pretend the data looks like this:
>
> Q8              Q9
> --              --
> q8string1       q9string1
> q8string2       q9string2
> q8string3       q3string3
>
> I need a dataset that looks like this:
>
> --
> q8string1
> q8string2
> q8string3
> q9string1
> q9string2
> q9string3
>
> Hopefully that's more clear.
>
> Mark
>
> Ed Heaton wrote:
>
> > Mark,
> >
> > You're pretty vague here.  Are the numbers character or numeric?  You could
> > use
> >
> > Q8Q9 = Q8 + Q9 ;
> >
> > or
> >
> > Q8Q9 = trim(Q8) || Q9 ;
> >
> > or
> >
> > Q8Q9 = 100 * Q8 + Q9 ;
> >
> > or
> >
> > Q8Q9 = Q8 + Q9/100 ;
> >
> > or
> >
> > Data ... ;
> >    Set ... ;
> >    Q8Q9 = Q8 ;  Output ;
> >    Q8Q9 = Q9 ;  Output ;
> > Run ;
> >
> > I don't have a clue what you want.
> >
> > Ed
> >
> > -----Original Message-----
> > From: Mark Biek [mailto: XXXX@XXXXX.COM ]
> > Sent: Thursday, May 06, 2004 11:53 AM
> > To:  XXXX@XXXXX.COM 
> > Subject: Best way to combine 2 columns of data into 1 column
> >
> >
> > I have a dataset that has the following columns:
> > ID      Q8      Q9
> >
> > I'm trying to come up with something so that I end up with a dataset
> > with a single column for all values of Q8 & Q9.  I though proc transpose
> > might do it but I haven't had much luck that way.
> >
> > What's the easiest way to combine the contents of 2 columns to make 1
> > column that has all values from both?
> >
> > Mark
> > --
> > Mark Biek
> > The Stevenson Company
> > 8700 Westport Rd. Ste. 200
> > Louisville, KY 40242-3100
> > (502) 429-9060 ext 251
> >
>
> --
> Mark Biek
> The Stevenson Company
> 8700 Westport Rd. Ste. 200
> Louisville, KY 40242-3100
> (502) 429-9060 ext 251



5. Combining columns from multiple rows into a column separated

6. Combining columns from multiple rows into a column separated by a comma

How do I combine columns from multiple rows into a column separated by
a comma, by a field
For Example

Field1    Field2

 A           111
 A           222
 A           333
 A           444
 B           555
 B           666

I want the result to show up like

A     111,222,333,444
B      555,666

Thanks in advance

Sam

7. Moving Data from one column to another column

8. Split data from one column to multiple column

Dear all,

My Query is i have to split data into multiple column
like i have one variable abc in this variable data in 4 digit like 1234
then i have to change 1 char in one column sec char in to sec column
and 3,4 in single column it means i have to split 4 digit data into
three varible plz send me the reply