Hi ,
I have a dataset where Amt columns are in form of values and i want output to look like when Flag is yes then format amount fields with dollar sign and Falg is N then with % sign
T3 = T1/T2
Test1
SPP | SLN | Amt1 | Amt2 | T1 | T2 | Flag |
650 | 300 | 20 | 53 | 15 | 24 | Y |
325 | 250 | 52 | 87 | 10 | 32 | N |
Output should look like
SPP | SLN | Amt1 | Amt2 | T3 | Flag |
650 | 300 | 20$ | 53$ | 15$/24$ | Y |
325 | 250 | 52% | 87% | 10%/32% | N
|
Can anyone please help
Is this what you are looking for?
No sure why you are doing this, so there might be a better solution
data have ;
infile cards ;
input amt1 amt2 t1 t2 flag $ ;
cards ;
20 53 15 24 Y
52 87 10 32 N
;
data want ;
length
amt1F $10
amt2F $10
T3 $100 ;
set have ;
if flag="Y" then
symbol="$" ;
else
symbol="%" ;
amt1F=trim(putn(amt1,"8."))!!symbol ;
amt2F=trim(putn(amt2,"8."))!!symbol ;
t3=trim(putn(t1,"8."))!!symbol!!"/"!!trim(left(putn(t2,"8.")))!!symbol ;
put amt1F= amt2F= t3= ;
run ;
You want Amt1 and Amt2 to be numeric and T3 to be character, correct?
So if flag = 'Y' you want to attach "$" to Amt1 and Amt2 and combine T1 and T2 and if flag = "N" you want to "%" instead of "$". Right?
You do want a report, correct?
Is this what you are looking for?
No sure why you are doing this, so there might be a better solution
data have ;
infile cards ;
input amt1 amt2 t1 t2 flag $ ;
cards ;
20 53 15 24 Y
52 87 10 32 N
;
data want ;
length
amt1F $10
amt2F $10
T3 $100 ;
set have ;
if flag="Y" then
symbol="$" ;
else
symbol="%" ;
amt1F=trim(putn(amt1,"8."))!!symbol ;
amt2F=trim(putn(amt2,"8."))!!symbol ;
t3=trim(putn(t1,"8."))!!symbol!!"/"!!trim(left(putn(t2,"8.")))!!symbol ;
put amt1F= amt2F= t3= ;
run ;
Thank you so much for all help . This is right . I will apply same logic to my data and check . Will update .
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.