BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jb9977
Fluorite | Level 6

I have two tables on is

id  value

1     aa

2     bb

3     cc

the other is

No    value

25      aa

25      bb

25       cc

26       aa

26      bb

26      cc

I need a output like this

id  value     no   value    no   value

1     aa        25      aa       26     aa

2     bb         25      bb       26     bb

3     cc         25       cc        26     cc

 

Thanks.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

Please try the below code, you will get the expected output. however the variable names will be different. So if you want to display the variable names same then please update the label statement as mentioned in the code.

 

 

data have1;
input id  value$;
cards;
1     aa
2     bb
3     cc
;
data have2;
input No    value$;
cards;
25      aa
25      bb
25       cc
26       aa
26      bb
26      cc
;

proc sort data=have1;
by value;
run;

proc sort data=have2;
by value;
run;

data have;
merge have1 have2;
by value;
run;

data have;
set have;
by value;
retain num;
if first.value then num=1;
else num+1;
run;

data want;
set have;
array val(*) $ value1-value2;
array nos(*)$ no1-no2;
by value notsorted;
retain value1-value2 no1-no2;
if first.value then do;
call missing (of val(*));
call missing (of nos(*));
end;
val(num)=value;
nos(num)=no;
if last.value;
drop num;
label value1='Value'
      value2='Value'
      no1='No'
      no2='No'; run;

image.png

Thanks,
Jag

View solution in original post

4 REPLIES 4
ballardw
Super User

If you want a data set as output you should provide some additional variable names as you can only have one variable named "value" in a data set.

Or do you want a report with text?

LinusH
Tourmaline | Level 20
To me your output looms like a report. If that's your goal I suggest that you simply first join on the columns "value", and then use e.g. PROC REPORT to get the desired layout.
Data never sleeps
Reeza
Super User

Do you need a dataset or a report that looks like that? 

 

Jagadishkatam
Amethyst | Level 16

Please try the below code, you will get the expected output. however the variable names will be different. So if you want to display the variable names same then please update the label statement as mentioned in the code.

 

 

data have1;
input id  value$;
cards;
1     aa
2     bb
3     cc
;
data have2;
input No    value$;
cards;
25      aa
25      bb
25       cc
26       aa
26      bb
26      cc
;

proc sort data=have1;
by value;
run;

proc sort data=have2;
by value;
run;

data have;
merge have1 have2;
by value;
run;

data have;
set have;
by value;
retain num;
if first.value then num=1;
else num+1;
run;

data want;
set have;
array val(*) $ value1-value2;
array nos(*)$ no1-no2;
by value notsorted;
retain value1-value2 no1-no2;
if first.value then do;
call missing (of val(*));
call missing (of nos(*));
end;
val(num)=value;
nos(num)=no;
if last.value;
drop num;
label value1='Value'
      value2='Value'
      no1='No'
      no2='No'; run;

image.png

Thanks,
Jag

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 1182 views
  • 1 like
  • 5 in conversation