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

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 

SPPSLNAmt1Amt2T1T2Flag
65030020531524Y
32525052871032N

 

Output should look like 

SPPSLNAmt1Amt2T3Flag
65030020$53$15$/24$Y
32525052%87%10%/32%

N

 

 

Can anyone please help 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
AMSAS
SAS Super FREQ

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 ;

View solution in original post

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

You want Amt1 and Amt2 to be numeric and T3 to be character, correct?

andreas_lds
Jade | Level 19

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?

jhh197
Pyrite | Level 9
Yes . Right .
AMSAS
SAS Super FREQ

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 ;
jhh197
Pyrite | Level 9

Thank you so much for all help . This is right . I will apply same logic to my data and check . Will update .

jhh197
Pyrite | Level 9
Thank you so much for all your help . It worked 🙂

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1425 views
  • 6 likes
  • 4 in conversation