Hi Everyone,
I want to extract text in between 2 character ":" and "-"
as below:
For "82 : B2310 - I&g9ST LOE, - Project /Task Lead-" the new variable will be B2310
The could be multiple "-" but only the first "-" matter.
The output file should be below:
B2310
B2310
B2330
B2350
Thank you,
HC
data want;
set test;
where_colon=find(answer,':');
where_hyphen=find(answer,'-');
desired_output1= strip(substr(answer,where_colon+1,where_colon+4));
desired_output2= strip(substr(answer,where_colon+1,where_hyphen-where_colon-1));
run;
DATA test;
INFILE DATALINES DELIMITER=',' DSD;
INPUT answer & $50.;
DATALINES;
"82 : B2310 - I&g9ST LOE, Project /Task Lead-"
"83 : B2310 - I&fgST LOE, Quality /IV&V Manager-"
"84 : B2330 - I&fgST LOE, Expert 2-"
"85 : B2350 - I&ST LOE, Expert 3-"
;
RUN;
UNTESTED CODE
data want; set test; where_colon=find(answer,':'); where_hyphen=find(answer,'-'); desired_output= strip(substr(answer,where_colon+1,where_hypen-where_colon)); run;
UNTESTED CODE
data want; set test; where_colon=find(answer,':'); where_hyphen=find(answer,'-'); desired_output= strip(substr(answer,where_colon+1,where_hypen-where_colon)); run;
Use the SCAN() function and the third parameter allows you to set multiple custom delimiters.
want = scan(answer, 2, ":-");
Thanks a lot!!!
HC
@Reeza wrote:
Use the SCAN() function and the third parameter allows you to set multiple custom delimiters.
want = scan(answer, 2, ":-");
I like it. Easier than my solution.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.