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,
data have;
input userid $40.;
cards;
:sassrv
:datapo@saspw
74064:datapo@saspw
;
run;
data want;
set have;
new=prxchange('s/^://',1,userid);
run;
Why didn't it work with compress?
You need to use it in conjunction with if, substr and cats.
Thanks for your response.
May I request to give a code snippet as I was doing something wrong with these function.
data have;
input userid $40.;
cards;
:sassrv
:datapo@saspw
74064:datapo@saspw
;
run;
data want;
set have;
new=prxchange('s/^://',1,userid);
run;
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.