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

Hi,

I have 8 observations of clinical results expresed in expenential counts (e.g., 1.94E+4) plus their corresponding log values within parentheses, e.g., (4.29) in a chracter string. I would like to parse this string and extract the two sets of values into two separate variables (counts, logCounts). I think a perl or scan function can help me with this. A "no results" would also be carried forward to the variable.

 

string                             wanted result: Counts          wanted result: logCounts

"1.94E+4 (4.29)"            1.94E+4                               4.29
"5.54E+4 (4.74)"            5.54E+4                              4.74
"1.19E+4 (4.08)"            1.19E+4                              4.08
"2.76E+4 (4.44)"             2.76E+4                             4.44
"8.29E+4 (4.92)"             8.29E+4                             4.92
"< 2.00E+1 (1.30)"          <2.00E+1                           1.30
"2.99E+5 (5.48)"             2.99E+5                              5.48

"No results found"           No results found                 No results found

 

I am running SAS 9.4 on Windows 7. 

 

Thanks

 

--tim

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data in the form of a datastep!

 

 

As such this code is untested, and I assume the two wants are string:

data want;
  set have;
  counts=scan(string,1,"(");
  logcounts=compress(scan(string,2,"("),")");
run;

View solution in original post

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data in the form of a datastep!

 

 

As such this code is untested, and I assume the two wants are string:

data want;
  set have;
  counts=scan(string,1,"(");
  logcounts=compress(scan(string,2,"("),")");
run;
PeterClemmensen
Tourmaline | Level 20

Like this?

 

data have;
input string $20.;
infile datalines dlm = ',';
datalines;
1.94E+4 (4.29)
5.54E+4 (4.74)
1.19E+4 (4.08)
2.76E+4 (4.44)
8.29E+4 (4.92)
<2.00E+1 (1.30)
2.99E+5 (5.48)
No results found
;

data want;
	set have;
	
	if string = 'No results found' then do;
		Wanted_Counts = string;
		Wanted_LogCounts = string;
	end;

	else do;
		Wanted_Counts = scan(string,1,' ');
		Wanted_LogCounts = compress(compress(scan(string,2,' '),'(',),')');
	end;
run;

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!

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
  • 2 replies
  • 671 views
  • 0 likes
  • 3 in conversation