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 .
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.