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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 961 views
  • 6 likes
  • 4 in conversation