BookmarkSubscribeRSS Feed
keen_sas
Quartz | Level 8

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";

 

 

4 REPLIES 4
andreas_lds
Jade | Level 19

Sorry, but i don't understand what you expect as result, please clarify.

keen_sas
Quartz | Level 8

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 .

 

PaigeMiller
Diamond | Level 26

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?

--
Paige Miller
Reeza
Super User

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-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!

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
  • 4 replies
  • 3259 views
  • 0 likes
  • 4 in conversation