BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
kcvaldez98
Obsidian | Level 7

 

I am trying to extract the lower bounds of a 95% CI from a character string and I am trying to extract the number while making it numeric.

 

The character string I am extracting from is "95% C.I.: 7.7 - 10.7" I am trying to just keep the 7.7 and make it numeric.

The code I put in is:

 

DATA WORK.CI;
SET OLD DATA;
countylowerCI = SUBSTR(SCAN(countyCI, 1, ':-'));
RUN;
 
What am I doing wrong?
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Use INPUT to convert a character variable to numeric, not sure what is the purpose of SUBSTR.

lowerCI = input(scan(countyCI, 2, ':-'), best12.);

Note that I would recommend running the scan function first to verify what it's returning for your text and then try the conversion.

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

@kcvaldez98 wrote:
 
countylowerCI = SUBSTR(SCAN(countyCI, 1, ':-'));

 

Does this help you figure it out?

 

data a;
    countyci="95% C.I.: 7.7 - 10.7";
    word1=scan(countyCI, 1, ':-');
    word2=scan(countyCI, 2, ':-');
    word3=scan(countyCI, 3, ':-');
run;

 

The above code does not return a numeric value, it returns a character string, but I'm guessing you make that change after you figure it out.

 

Why are you getting confidence intervals as text strings? All SAS procedures can get the actual numerical value as output, that's a much better way to go.

--
Paige Miller
Reeza
Super User
Use INPUT to convert a character variable to numeric, not sure what is the purpose of SUBSTR.

lowerCI = input(scan(countyCI, 2, ':-'), best12.);

Note that I would recommend running the scan function first to verify what it's returning for your text and then try the conversion.
antonbcristina
SAS Employee

As suggested, do this in stages. First scan the character string, confirming you have the right number (as a character string), then convert it using the INPUT function. 

 

DATA CI;
	countyCI = "95% C.I.: 7.7 - 10.7";
	countylowerCI_char = SCAN(countyCI, 2, ':-');
	countylowerCI_num  = input(countylowerCI_char,best10.);
RUN;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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