Architecting, installing and maintaining your SAS environment

concatenation

Accepted Solution Solved
Reply
Contributor
Posts: 71
Accepted Solution

concatenation

Hi,

I'm having two data files of two months. One is july and august.

Using proc sql I combines these two data sets

select * from

                 ( select depnto,

                             comm

                   from emp_aug13)

                  union all

                 ( select depnto,

                             comm

                   from emp_Jun13);

I got  output

deptno  Comm

  10      1000

  20      3000

  30      1500

  10       500

  20       190

  30       250

Loking for output ,

      Aug          Jul

deptno  Comm   deptno  Comm

  10     1000           10       500

  20     3000           20       190

  30     1500           30       250

Can any one share me hints to achive this.

regards,

venky


Accepted Solutions
Solution
‎09-18-2013 10:14 AM
Super Contributor
Posts: 1,636

Re: concatenation

an example:

data one;

input id var;

cards;

1 20

2 30

3 40

;

data two;

input id var;

cards;

1 200

2 300

3 400

;

proc sql;

select one.*,two.*

  from one,two

  where one.id=two.id;

quit;

                                                 id       var        id       var

                                        

                                                 1        20         1       200

                                                 2        30         2       300

                                                 3        40         3       400

View solution in original post


All Replies
Solution
‎09-18-2013 10:14 AM
Super Contributor
Posts: 1,636

Re: concatenation

an example:

data one;

input id var;

cards;

1 20

2 30

3 40

;

data two;

input id var;

cards;

1 200

2 300

3 400

;

proc sql;

select one.*,two.*

  from one,two

  where one.id=two.id;

quit;

                                                 id       var        id       var

                                        

                                                 1        20         1       200

                                                 2        30         2       300

                                                 3        40         3       400

Super User
Posts: 5,429

Re: concatenation

Your desired output looks like a report, not a stored data set.

Take a look at PROC REPORT, potentially PROC TABULATE.

Data never sleeps
Occasional Contributor
Posts: 8

Re: concatenation

use 'comm' variable as commAug ,commJun in any in the data. you can not keep two variables on the same name.

Else use proc report

proc sql;

select emp_aug13.*,emp_Jun13.*

  from emp_aug13,emp_Jun13

  where emp_aug13.depnto=emp_Jun13.depnto;

quit;

deptno  commAug commJun

  10     1000                 500

  20     3000                 190

  30     1500                  250

Contributor
Posts: 71

Re: concatenation

Posted in reply to Amarnath7

Thank you for the help. I got the output as you suggested me.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 392 views
  • 3 likes
  • 4 in conversation