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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 526 views
  • 0 likes
  • 3 in conversation