BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I've a dataset similar to:
A B C D
a1 b1 red .
a1 b1 blue .
a1 b1 gren .
a1 b1 yellow 123
a1 b2 white .
a1 b2 red .
a1 b2 blue .
a1 b2 green 456
a1 b2 white .


I am looking for output similar to :

A B C D
a1 b1 red 123
a1 b1 blue 123
a1 b1 gren 123
a1 b1 yellow 123
a1 b2 white 456
a1 b2 red 456
a1 b2 blue 456
a1 b2 green 456
a1 b2 white 456

Thanks
4 REPLIES 4
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Consider using PROC SQL with a JOIN or use DATA step (with sorted input files) and the MERGE with a BY statement. Check the SAS DOC or you can find useful reference material at the SAS support http://support.sas.com/ website.

Also, you need only post in one (1) forum for this type of query.

Scott Barry
SBBWorks, Inc. Message was edited by: sbb
Ksharp
Super User
I think sbb has got the right idea here.
It looks like each b group has the same d value , is it right?
if it is. the code is

[pre]
data temp;
input a $ b $ c $ d ;
datalines;
a1 b1 red .
a1 b1 blue .
a1 b1 gren .
a1 b1 yellow 123
a1 b2 white .
a1 b2 red .
a1 b2 blue .
a1 b2 green 456
a1 b2 white .
;
run;
data index;
set temp;
if not missing(d);
keep b d;
run;
proc sort data=temp;
by b;
run;
proc sort data=index;
by b;
run;
data merged;
merge temp(drop = d) index;
by b;
run;
proc print;
run;
[/pre]

Ksharp
P_J
Calcite | Level 5 P_J
Calcite | Level 5
Hope codes below would help,

data temp;
input a $ b $ c $ d ;
datalines;
a1 b1 red .
a1 b1 blue .
a1 b1 gren .
a1 b1 yellow 123
a1 b2 white .
a1 b2 red .
a1 b2 blue .
a1 b2 green 456
a1 b2 white .
;;;;
run;

proc sort data= temp;
by a b descending d;
run;

data want(drop=dd);
set temp;
by a b descending d;
retain dd;
if first.b then dd= d;
else d =dd;
run;
deleted_user
Not applicable
Thanks everyone for your help ! I really appreciate you guys.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 1722 views
  • 0 likes
  • 4 in conversation