BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasbanker
Calcite | Level 5

I have a source table that looks like the following "TestIN".

I want to read the file and create the output shown in TestOUT.

I assume it requires grouping and use of the Max function, but I don't know how to write the code.

I'm a newbie with no formal training, and any help will be appreciated.

Source Input File:  "TestIN"
AcctIDNameLocationclrRedclrBlueclrGreen
100BobMARed
100BobMABlue
200JohnNCRed
200JohnNCGreen
300FrankVARed
300FrankVABlue
300FrankVAGreen
Desired Output:  TestOUT
AcctIDNameLocationclrRedclrBlueclrGreen
100BobMARedBlue
200JohnNCRedGreen
300FrankVARedBlueGreen
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Two way. which one you like better ?

data have;
input AcctID     Name $     Location $     clrRed $     clrBlue     $ clrGreen $;
cards;
100     Bob     MA     Red     . .
100     Bob     MA     .     Blue     .
200     John     NC     Red     . .     
200     John     NC          . .     Green
300     Frank     VA     Red     . .
300     Frank     VA     .     Blue     .
300     Frank     VA     .     .     Green
;
run;

proc sql;
create table want1 as
 select AcctID,Name,Location,max(clrRed) as clrRed,max(clrBlue) as clrBlue,max(clrGreen) as clrGreen
  from have
   group by AcctID,Name,Location;
quit;

data want2;
 update have(obs=0) have;
 by AcctID Name Location;
run;

Xia Keshan

View solution in original post

2 REPLIES 2
Ksharp
Super User

Two way. which one you like better ?

data have;
input AcctID     Name $     Location $     clrRed $     clrBlue     $ clrGreen $;
cards;
100     Bob     MA     Red     . .
100     Bob     MA     .     Blue     .
200     John     NC     Red     . .     
200     John     NC          . .     Green
300     Frank     VA     Red     . .
300     Frank     VA     .     Blue     .
300     Frank     VA     .     .     Green
;
run;

proc sql;
create table want1 as
 select AcctID,Name,Location,max(clrRed) as clrRed,max(clrBlue) as clrBlue,max(clrGreen) as clrGreen
  from have
   group by AcctID,Name,Location;
quit;

data want2;
 update have(obs=0) have;
 by AcctID Name Location;
run;

Xia Keshan

sasbanker
Calcite | Level 5

Great!  Thanks.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2 replies
  • 896 views
  • 0 likes
  • 2 in conversation