Desktop productivity for business analysts and programmers

switching the values of the columns

Reply
Contributor
Posts: 20

switching the values of the columns

Hi,

33822730 12/27/2007 xyz Approval
33822730 2/4/2009 xyz Referral

I have to switch the values of APPROVAL and REFERRAL depending on date.For each id the first date value should be approval and second date value should be Refferal,only if approval and refferal are present for perticular id.

How can acheive this using EG.

reddy
Super Contributor
Super Contributor
Posts: 365

Re: switching the values of the columns

Hello Reddy19,

This is a solution:
[pre]
data i;
input id date ANYDTDTE10. field $ Status $ 25-32;
format date date7.;
datalines;
33822730 12/27/2007 xyz Approval
33822730 2/3/2009 xyz
33822730 2/4/2009 xyz Referral
33822730 2/5/2009 xyz
run;
proc sort data=i;
by id date;
run;
data r;
set i;
if FIRST.id and UPCASE(Status) in ("APPROVAL" "REFERRAL") then s="Referral";
else if UPCASE(Status) in ("APPROVAL" "REFERRAL") then s="Approval";
by id;
run;
[/pre]
Sincerely,
SPR
Contributor
Posts: 20

Re: switching the values of the columns

Through programming i will be able to do it.

But using EG(point and click interface),i'm not able to figure it out...can you please suggest me how i could do this using EG.

Thanks a lot,
reddy
Respected Advisor
Posts: 3,839

Re: switching the values of the columns

Hi

The query wizard in EG generates SQL code.
Writing logic in SQL where you need to do things on a "first" and "second" row is often tricky. Procedural languages like Base SAS are much better suited for this.

So even with the best (SQL) query wizard it would be rather hard to set up this query.

Why not use the possibilities EG gives you - which in this case would be the programming window.

HTH
Patrick
Ask a Question
Discussion stats
  • 3 replies
  • 126 views
  • 0 likes
  • 3 in conversation