Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 715807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:13:43+00:00 2026-05-14T05:13:43+00:00

I am trying to manipulate a conditional string outputted from SAS into the right

  • 0

I am trying to manipulate a conditional string outputted from SAS into the right format for a conditional statement in R. Here is an example of the conditional outputted from SAS:

. < var1_a<=80 and var2_a>50.8

I’ve written a function that handles some of the transformation necessary:

conditonalsub <- function(x) {
subnew <- gsub("<=", " <= ", x)
subnew <- gsub(">=", " >= ", subnew)
subnew <- gsub(">", " > ", subnew)
subnew <- gsub("and", "&", subnew)
subnew <- gsub("\\.\\s", "NA ", subnew)
return(subnew)

which produces the following string:

NA < var1_a <= 80 & var2_a > 50.8

I am using these conditional statements to subset the observations of a data frame. So in this example I want R to select all observations with var1_a values that are either missing or less than or equal to 80 AND have var2_a greater than 50.8. How can I modify the above function so that I get a conditional statement that is able to take missing values like the var1_a portion of the conditional statement above? My guess is the format of the new conditional statement would look something like this?

(var1_a == NA | var1_a <= 80) & (var2_a > 50.8) 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:13:43+00:00Added an answer on May 14, 2026 at 5:13 am

    This is not a true answer, but I think this problem is more complicated than what you present.

    1. Missing values act somewhat strange in SAS. For comparisons, they are equivalent to negative infinity. So a missing value is smaller than any non-missing number, but not smaller than a missing number. So the . < var1_a<=80 statement is written this way to avoid selecting missing values, and not include them. This also means that the real problem is with inoccuous looking statements such as a<10 which will evaluate to TRUE in SAS if a is missing, but not so in R.

    2. On the other hand, the 2 < a < 4 syntax for getting the values between 2 and 4 is allowed in SAS, but not in R, so you will have to find a way to detect this and all its variations.

    3. Depending how general you want to get, you have to recode the alternative ways SAS can denote comparisons as well (EQ, NE, GEQ, etc).

    So unless your set of SAS logical statements has very restricted syntax, you will have lots of trouble.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to manipulate a string to a format of regexp String months1
I'm trying to manipulate a string.. For example: string DiagnosesString 250.00 03 350.0001 450.00
Here's the deal. I have a large character array and am trying to manipulate
I am trying to manipulate a file and create a new folder from within
I am trying manipulate Jquery Infinite Carousel into dynamically resizing the image container based
I am trying to manipulate a string using Jython, I have included below an
I'm trying to manipulate the output of an SQLite query so into two parts
I am trying to manipulate the hash returned from Yahoo Finance for their Standard
Here is an example of the type of data that I am trying to
I have been trying to manipulate content that is loaded into jQuery UI tabs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.