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

I've a data like below. Here I need to remove only the colon (:) in the variable 'userid' if it is a first character.

userid
:sassrv
:datapo@saspw
74064:datapo@saspw

I need the data as below.

userid
sassrv
datapo@saspw
74064:datapo@saspw

I tried with compress function to achieve this, but could not succeed. Please advise,

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Code: Program

data have;
input userid $40.;
cards;
:sassrv
:datapo@saspw
74064:datapo@saspw
;
run;
data want;
set have;
new=prxchange('s/^://',1,userid);
run;

View solution in original post

4 REPLIES 4
LinusH
Tourmaline | Level 20

Why didn't it work with compress?

You need to use it in conjunction with if, substr and cats.

Data never sleeps
Babloo
Rhodochrosite | Level 12

Thanks for your response.

May I request to give a code snippet as I was doing something wrong with these function.

Ksharp
Super User

Code: Program

data have;
input userid $40.;
cards;
:sassrv
:datapo@saspw
74064:datapo@saspw
;
run;
data want;
set have;
new=prxchange('s/^://',1,userid);
run;
MadhuKorni
Quartz | Level 8

data log_analysis;

infile '/usr/sas/sas_config/Lev1/SASApp/Logs/SASApp_STP_2015-08-19_tmp1_19142.log' truncover;

input var : $ 3000.;

var1 = _infile_;

if var1 = :'2015';

Date_With_TimeStamp = scan(var1,1," ");

Status = scan(var1,2," ");

Processid = scan(var1,3," ");

if substr(scan(var1,4," "),1,1)=':' then userid =substr(scan(var1,4," "),2) ;

else userid = scan(var1,4," ");

Details = scan(var1,-1,'-');

drop var var1;

run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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