Character Values/observations in variables can be in different cases like upper/mixed/lower, but when we execute them through SAS logical statements data wont be read properly, to create new variables, since they may not match as per the data values. To avoid this case sensitive we either place upcase/lowcase to avoid the case sensitivity while reading the data.Below are some of the scenarios of different case sensitive conditions present, that have to be read without missing any of the vales due to case sensitivity.
HAVE | WANT |
country = "AUSTRALIA" | upcase(country)=upcase("AUSTRALIA") |
ACTION = "NOT Applicable" | upcase(ACTION) = upcase("NOT Applicable") |
missing(STATE) | missing(STATE) |
country = "AustRalia" and state not in ("SydNey" "melbourNE") | upcase(country) = upcase("AustRalia)" and upcase(state) not in upcase(("SydNey" "melbourNE")) |
OUTCOME = "NOT Recovered/not resolved" and STABLE ne "N" | upcase(OUTCOME) = upcase("NOT Recovered/not resolved") and upcase(STABLE) ne upcase("N") |
OUTCOME = "recovered/RESOLVED with sequelea" and not missing(OUT_DY) | OUTCOME = "recovered/RESOLVED with sequelea" and not missing(OUT_DY) |
data have ;
length text $200.;
text='country = "AUSTRALIA"';output;
text='ACTION = "NOT Applicable"';output;
text='missing(STATE)';output;
text="country = 'AustRalia' and state not in ('SydNey' 'melbourNE')";output;
text="OUTCOME = 'NOT Recovered/not resolved' and STABLE ne 'N' ";output;
text='OUTCOME = "recovered/RESOLVED with sequelea" and not missing(OUT_DY)';output;
run ;
Would like to convert as shown in HAVE column to frame a proper SAS logical conditions to read the data and create new variables as below.Any suggestions .
if upcase(country)=upcase("AUstrALIA") then value="Good";
if upcase(ACTION) = upcase("NOT Applicable") then result="NA";
Sorry, but i don't understand what you expect as result, please clarify.
For example i have country variable with values "AusTraLia" in mixed case, when i apply the logic if country="AUSTRALIA" then output dsn; i wont get the result/output because it is in Mixed case. From the above example HAVE are the values/conditioins which are provided to the programmer to extract from the respective dataset,but the programmer is not aware of the CASE of the values present in the dataset. To extract the values from the dataset based on the HAVE column one has to apply some uniform case on the dataset and also on the condition, which have provided as example in WANT column in the above example. The values in HAVE should be converted to values WANT to extract the observations/values from the dataset .
Normally we talk about records having a specified value(s) of a given variable, that's the condition you want to meet.
But you're not talking about values of a variable. You seem to be talking about modifying text strings to provide a new text string containing valid SAS syntax that will find certain values of a variable. Is that correct?
This is a problem that will be difficult to correct. You're much better going back and manually cleaning up your code/data unfortunately.
One brute force method is to upcase all character variables and upcase everything within quotation marks but that changes your raw data so not sure that's an acceptable solution. You could create a duplicate of each character variable and use those instead but still a bit of work to change the variable names in the code.
@keen_sas wrote:
Character Values/observations in variables can be in different cases like upper/mixed/lower, but when we execute them through SAS logical statements data wont be read properly, to create new variables, since they may not match as per the data values. To avoid this case sensitive we either place upcase/lowcase to avoid the case sensitivity while reading the data.Below are some of the scenarios of different case sensitive conditions present, that have to be read without missing any of the vales due to case sensitivity.
HAVE WANT country = "AUSTRALIA" upcase(country)=upcase("AUSTRALIA") ACTION = "NOT Applicable" upcase(ACTION) = upcase("NOT Applicable") missing(STATE) missing(STATE) country = "AustRalia" and state not in ("SydNey" "melbourNE") upcase(country) = upcase("AustRalia)" and upcase(state) not in upcase(("SydNey" "melbourNE")) OUTCOME = "NOT Recovered/not resolved" and STABLE ne "N" upcase(OUTCOME) = upcase("NOT Recovered/not resolved") and upcase(STABLE) ne upcase("N") OUTCOME = "recovered/RESOLVED with sequelea" and not missing(OUT_DY) OUTCOME = "recovered/RESOLVED with sequelea" and not missing(OUT_DY)
data have ;
length text $200.;
text='country = "AUSTRALIA"';output;
text='ACTION = "NOT Applicable"';output;
text='missing(STATE)';output;
text="country = 'AustRalia' and state not in ('SydNey' 'melbourNE')";output;
text="OUTCOME = 'NOT Recovered/not resolved' and STABLE ne 'N' ";output;
text='OUTCOME = "recovered/RESOLVED with sequelea" and not missing(OUT_DY)';output;
run ;
Would like to convert as shown in HAVE column to frame a proper SAS logical conditions to read the data and create new variables as below.Any suggestions .
if upcase(country)=upcase("AUstrALIA") then value="Good";
if upcase(ACTION) = upcase("NOT Applicable") then result="NA";
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.