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

hi , I'm trying to concat three values, into a new value, where I want them spaced in such a fashion that when looking at the strings within the variable denominated say by a | (pipe), they would be spaced in a consistent manner... Ie, the date would  always begin from end of say a $200 length NewVar, or always begining at say , digit space +185. 

 

Current code used to concat 3 columns: NewVar= CATX(' | ', ID ,IssueName,put(CurrentTargetDate,mmddyy10.));

run;

 

Current output:

149 | SOL Address Change Issue | 12/28/2018
196 | BOND - Delayed File Processing | 01/11/2019
58 | Document Retention | 03/04/2019

 

Wanted output:

149 | SOL Address Change Issue |           12/28/2018

196 | BOND - Delayed File Processing |    01/11/2019
58   | Document Retention |                        03/04/2019

 

 

Sample data 

 

ID IssueName CurrentTargetDate
179 MRV Error Message on SPOON Application in Store 12/7/2018
195 Credit Bureau Impact due to CCT Change 12/14/2018
165 SPP Segment Pricing on Passport Infinite 12/21/2018
203 GM/SOF Bounty and Incentive Control Enhancements 1/18/2019
156 Purchase Promo Reach Back 2/1/2019
185 OFG Team Member Promo 2/6/2019
153 PAD Issue for Visa Scene New Bin Number 2/8/2019
191 Promo Rate Display Location.com 2/8/2019
192 Duplicate Scotialine with Access Card Setups 2/8/2019

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

To get everything to line up, you need to know the maximum number of characters required by each variable.  In this example, I will use $50 as the length of IssueName.  To get everything to line up, you could use:

 

newvar = '     |                                                    |         ';
substr(newvar, 2, 3) = id;
substr(newvar, 7, 50) = IssueName;
substr(newvar, 61, 8) = put(CurrentTargetDate, mmddyy10.);

Once you are lining up the interior data, it is possible that you don't need the pipes any more.  But that would depend on where you are heading with this down the road.

 

The pipes are also going to line up in the code I supplied ... probably a better way than having the pipes switch position depending on the length of the variables.  But that can be changed if necessary.

View solution in original post

5 REPLIES 5
Reeza
Super User
So no trailing spaces, but maintain leading spaces? I think you need a different CAT function, try CATT instead?
brulard
Pyrite | Level 9
Thanks Reeza, let me consider that...
Astounding
PROC Star

To get everything to line up, you need to know the maximum number of characters required by each variable.  In this example, I will use $50 as the length of IssueName.  To get everything to line up, you could use:

 

newvar = '     |                                                    |         ';
substr(newvar, 2, 3) = id;
substr(newvar, 7, 50) = IssueName;
substr(newvar, 61, 8) = put(CurrentTargetDate, mmddyy10.);

Once you are lining up the interior data, it is possible that you don't need the pipes any more.  But that would depend on where you are heading with this down the road.

 

The pipes are also going to line up in the code I supplied ... probably a better way than having the pipes switch position depending on the length of the variables.  But that can be changed if necessary.

ballardw
Super User

It might help to include your worked examples in the "Sample data". It is not clear as posted whether your worked examples would have removed things from the base data. Worked examples should always start with sample data.

Also you say "for example digit space +185". What do you want to happen if the concatenated bits of ID and Issue exceed 185 (or any given position)?

 

data have;
   infile datalines dlm='|';
   informat id best5. IssueName $100. CurrentTargetDate mmddyy10.;
   input id issuename currenttargetdate;
datalines;
179|MRV Error Message on SPOON Application in Store|12/7/2018
195|Credit Bureau Impact due to CCT Change|12/14/2018
165|SPP Segment Pricing on Passport Infinite|12/21/2018
203|GM/SOF Bounty and Incentive Control Enhancements|1/18/2019
156|Purchase Promo Reach Back|2/1/2019
185|OFG Team Member Promo|2/6/2019
153|PAD Issue for Visa Scene New Bin Number|2/8/2019
191|Promo Rate Display Location.com|2/8/2019
192|Duplicate Scotialine with Access Card Setups|2/8/2019
;
run;

data want;
   set have;
/*   file 'x:\data\junk.txt';*/
   length newvar $200.;
   datepos=185;
   x=length(catx('|',id, issuename) );
   newvar=catt(catx('|',id, issuename),cat('|',repeat(' ',datepos-(x+3)),put(currenttargetdate,mmddyy10.)) );
/*   put newvar;*/
   drop datepos x;
run;


Since it is going to be a tad difficult to verify that the data starts on col 185, the datepos variable if your issuename may contain digits you could remove the comments for the file and put statement and examine the result in an editor that shows the column positions.

 

brulard
Pyrite | Level 9

hi Ballardw, your solution works for me as well, thank you. Also, apologies for not including the example in sample data; I won't make this mistake again in future posts.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 1377 views
  • 3 likes
  • 4 in conversation