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.
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;
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?
Do you need a dataset or a report that looks like that?
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;
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.
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.