Help using Base SAS procedures

help in coding

Reply
N/A
Posts: 0

help in coding

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
Super Contributor
Super Contributor
Posts: 3,174

Re: help in coding

Posted in reply to deleted_user
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
Super User
Posts: 10,046

Re: help in coding

Posted in reply to deleted_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
Occasional Contributor P_J
Occasional Contributor
Posts: 10

Re: help in coding

Posted in reply to deleted_user
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;
N/A
Posts: 0

Re: help in coding

Thanks everyone for your help ! I really appreciate you guys.
Ask a Question
Discussion stats
  • 4 replies
  • 140 views
  • 0 likes
  • 4 in conversation