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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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