BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
RobertWF1
Quartz | Level 8

For example, in the following code notice how the table data_join contains multiple copies of the z values for A001 and B002.

 

Is it possible to just retain the first row of values from the matched data2 table? I'm outputting joined tables to Excel and so it's easier on the eyes if there aren't so many duplicate rows.

 

data data1;
input id :$4. x y;
cards;
A001 10 20
A001 30 40
A001 50 60
B002 1 2
B002 3 4
B002 5 6
;
run;

data data2;
input id :$4. z;
cards;
A001 1000
B002 2000
;
run;

proc sql;
create table data_join as
select *
from data1 a
inner join
data2 b
on a.id=b.id;
quit;
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Use PROC REPORT for the export:

ods xlsx file="/somewhere/file.xlsx";

proc report data=join;
column id x y z;
define id / group;
define x / display;
define y / display;
define z / group;
run;

ods excel close;

Untested, posted from my tablet.

View solution in original post

6 REPLIES 6
Kurt_Bremser
Super User

Use PROC REPORT for the export:

ods xlsx file="/somewhere/file.xlsx";

proc report data=join;
column id x y z;
define id / group;
define x / display;
define y / display;
define z / group;
run;

ods excel close;

Untested, posted from my tablet.

Reeza
Super User
X/Y seem arbitrary then. Usually there's some business rule that should apply.
If they're not required can you just drop them?
Or would an aggregation of X/Y make sense, sum, mean, min?
RobertWF1
Quartz | Level 8
I made up data for my question, but the X and Y columns I need to keep (they represent proc freq row count & percent data) and the Z column represents chi-squared statistics I'm attaching to the table.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 6 replies
  • 1006 views
  • 5 likes
  • 3 in conversation