Hi ,
I have a dataset which has rpflag , rp1,rp2,rp3,rp4 amounts in numeric format . I want to create rp5 column
case when rpflag = 'Y' then (TRIM(put(rp1,8.)))||'/'||(TRIM(put(rp2,8..)))
when rpflag = 'N' then (TRIM(put(rp3,8.)))||'/'||(TRIM(put(rp4,8.)))
else '' end as rp5
RPFlag | RP1 | RP2 | RP3 | RP4 | RP5 |
Y | 20 | 35 | 0 | 0 | 20/35 |
N | 0 | 0 | 20 | 30 | 20/30 |
N | 0 | 0 | 0 | 0 | 0/0 |
Y | 0 | 0 | 0 | 0 | 0/0 |
Y | 56 | 33 | 0 | 0 | 56/33 |
Make sure to read the log and include in future posts.
You have two periods in the PUT statement.
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 68 69 70 proc sql; 71 create table want as 72 Select *, 73 case when rpflag = 'Y' then (TRIM(put(rp1,8.)))||'/'||(TRIM(put(rp2,8..))) _ 22 200 ERROR 22-322: Syntax error, expecting one of the following: ), -. ERROR 200-322: The symbol is not recognized and will be ignored.
That's fairly complicated coding though - using CATX() is preferable - it trims automatically and adds in the / in between.
This is cleaner IMO:
case when rpflag = 'Y' then catx('/', put(rp1, 8.), put(rp2, 8.))
when rpflag = 'N' then catx('/', put(rp1, 8.), put(rp2, 8.))
else '' end as rp6
@jhh197 wrote:
Hi ,
I have a dataset which has rpflag , rp1,rp2,rp3,rp4 amounts in numeric format . I want to create rp5 column
case when rpflag = 'Y' then (TRIM(put(rp1,8.)))||'/'||(TRIM(put(rp2,8..)))
when rpflag = 'N' then (TRIM(put(rp3,8.)))||'/'||(TRIM(put(rp4,8.)))
else '' end as rp5
RPFlag RP1 RP2 RP3 RP4 RP5 Y 20 35 0 0 20/35 N 0 0 20 30 20/30 N 0 0 0 0 0/0 Y 0 0 0 0 0/0 Y 56 33 0 0 56/33
Can anyone please help thank you
Does it have to be SQL code?
Make sure to read the log and include in future posts.
You have two periods in the PUT statement.
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 68 69 70 proc sql; 71 create table want as 72 Select *, 73 case when rpflag = 'Y' then (TRIM(put(rp1,8.)))||'/'||(TRIM(put(rp2,8..))) _ 22 200 ERROR 22-322: Syntax error, expecting one of the following: ), -. ERROR 200-322: The symbol is not recognized and will be ignored.
That's fairly complicated coding though - using CATX() is preferable - it trims automatically and adds in the / in between.
This is cleaner IMO:
case when rpflag = 'Y' then catx('/', put(rp1, 8.), put(rp2, 8.))
when rpflag = 'N' then catx('/', put(rp1, 8.), put(rp2, 8.))
else '' end as rp6
@jhh197 wrote:
Hi ,
I have a dataset which has rpflag , rp1,rp2,rp3,rp4 amounts in numeric format . I want to create rp5 column
case when rpflag = 'Y' then (TRIM(put(rp1,8.)))||'/'||(TRIM(put(rp2,8..)))
when rpflag = 'N' then (TRIM(put(rp3,8.)))||'/'||(TRIM(put(rp4,8.)))
else '' end as rp5
RPFlag RP1 RP2 RP3 RP4 RP5 Y 20 35 0 0 20/35 N 0 0 20 30 20/30 N 0 0 0 0 0/0 Y 0 0 0 0 0/0 Y 56 33 0 0 56/33
CATX() also does not require you to convert your numbers to strings. It will convert them automatically.
case when rpflag = 'Y' then catx('/', rp1,rp2)
when rpflag = 'N' then catx('/', rp3,rp4)
else ' '
end as rp6
Thank you everyone for helping 🙂
@Tom wrote:
CATX() also does not require you to convert your numbers to strings. It will convert them automatically.
case when rpflag = 'Y' then catx('/', rp1,rp2) when rpflag = 'N' then catx('/', rp3,rp4) else ' ' end as rp6
True and even simpler!
Thank you so much it worked
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.