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

Hi, I am having problems creating a new Column where I have to use a condition.

The context is: I have a table with the columns:

-ID

-credit card: it can be visa or master.

-amount: the amount in $

The objetive is not to be repetitive with the id if the client has visa and master. So I need 2 new columns where: if the credit card is from visa the new column "Amount_Visa" has the consolidated amount. And if its from master, the new column "Amount_Master" has its amount.

 

Now I have this:

IDCredit cardAmount
1visa230.60
1master456.30

 

And I need this:

IDCredit CardAmount_VisaAmount_Master
1Visa/Master230.60456.30

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20
data have;
input ID CreditCard $ Amount;
datalines;
1 visa   230.60
1 master 456.30
2 visa   230.60
2 master 456.30
;

data want;
   do until (last.ID);
      set have;
      by ID;
      CreditCard = "V/M";
      Amount_Visa	= Amount;
      Amount_Master = Amount;
   end;
   drop Amount;
run;

View solution in original post

7 REPLIES 7
novinosrin
Tourmaline | Level 20


data have;
input ID	Credit_card $	Amount;
cards;
1	visa	230.60
1	master	456.30
;

proc transpose data=have out=want(drop=_name_) prefix=Amount_;
 by id;
 var amount;
 id credit_card;
run;
proc print noobs;run;
PeterClemmensen
Tourmaline | Level 20
data have;
input ID CreditCard $ Amount;
datalines;
1 visa   230.60
1 master 456.30
2 visa   230.60
2 master 456.30
;

data want;
   do until (last.ID);
      set have;
      by ID;
      CreditCard = "V/M";
      Amount_Visa	= Amount;
      Amount_Master = Amount;
   end;
   drop Amount;
run;
clipsia
Fluorite | Level 6
Thank you both! But does it help if I have 3000 rows in this table??
PeterClemmensen
Tourmaline | Level 20

Both approaches handles 3000 obs easily. 

Kurt_Bremser
Super User

@clipsia wrote:
Thank you both! But does it help if I have 3000 rows in this table??

With a sufficiently slow computer, it might actually need more than 0.01 seconds.

clipsia
Fluorite | Level 6
I need a data set like this:
data want;
set table;
Amount_VISA=Amount;
if credit card='Visa' then Amount_VISA=Amount;
else Amount_MASTER=Amount;
drop amount;
run;
clipsia
Fluorite | Level 6
the important thing is to get off the duplicated ID rows

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 1530 views
  • 2 likes
  • 4 in conversation