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

I have a data set that has been compiled and I have to concatenate 3 of the fields. 

1 field is a character field : CUST-123

2nd Field is numeric: 56789

3rd field is a date field: 01/Sep/2020


proc sql;
select CUSTID||''||put(NUMBER_ID,10.)||''||put(CREATION_DATE_TIME,10.) from TABLE;
run;

 

Using the Put it changes the 2 non character fields to character but my result set comes out as:

CUST-123          6523574     22159

 

I tried trim but that doesnt work. I want the result set but without any spaces

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You can use CATT() instead which will trim all trailing spaces. Did you want the date as the SAS date value or a number such as 20200901?

 

proc sql;
select 
catt(custid, put(number_id, z10.), put(creation_date_time, yymmddn10.)) as want from table;
quit;
run;

@Jyuen204 wrote:

I have a data set that has been compiled and I have to concatenate 3 of the fields. 

1 field is a character field : CUST-123

2nd Field is numeric: 56789

3rd field is a date field: 01/Sep/2020


proc sql;
select CUSTID||''||put(NUMBER_ID,10.)||''||put(CREATION_DATE_TIME,10.) from TABLE;
run;

 

Using the Put it changes the 2 non character fields to character but my result set comes out as:

CUST-123          6523574     22159

 

I tried trim but that doesnt work. I want the result set but without any spaces


 

View solution in original post

7 REPLIES 7
PeterClemmensen
Tourmaline | Level 20

What does your desired result look like?

 

Where does 6523574 come from?

Jyuen204
Obsidian | Level 7

My end result that i want would be

CUST-123652357422159

 

6523574 is just an arbitrary number in my data

PeterClemmensen
Tourmaline | Level 20

See if this works for you.

 

data _null_;
   _1 = "CUST-123";
   _2 = 56789;
   _3 = '01sep2020'd;

   want = cats(_1, _2, _3);
   put want=;
run;
Jyuen204
Obsidian | Level 7

Would i just be using the field names ?

_1 = CUST_ID etc?

Reeza
Super User

You can use CATT() instead which will trim all trailing spaces. Did you want the date as the SAS date value or a number such as 20200901?

 

proc sql;
select 
catt(custid, put(number_id, z10.), put(creation_date_time, yymmddn10.)) as want from table;
quit;
run;

@Jyuen204 wrote:

I have a data set that has been compiled and I have to concatenate 3 of the fields. 

1 field is a character field : CUST-123

2nd Field is numeric: 56789

3rd field is a date field: 01/Sep/2020


proc sql;
select CUSTID||''||put(NUMBER_ID,10.)||''||put(CREATION_DATE_TIME,10.) from TABLE;
run;

 

Using the Put it changes the 2 non character fields to character but my result set comes out as:

CUST-123          6523574     22159

 

I tried trim but that doesnt work. I want the result set but without any spaces


 

Jyuen204
Obsidian | Level 7
Thanks i will give that a try. I used Compress() and that seems to have done the trick as well. Always good to have multiple solutions! Cheers everyone!
Reeza
Super User
COMPRESS will remove any internal spaces as well so it's not a robust solution IMO.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 7 replies
  • 900 views
  • 0 likes
  • 3 in conversation