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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 579 views
  • 0 likes
  • 3 in conversation