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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1917 views
  • 5 likes
  • 3 in conversation