- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi all SAS Users,
I have want to create a variable voi_and_acc=1
if GEOGN match one of some specific words
For example, I have some input specific words like: Argentina, AuStralia
GEOGN is ARGENTINA and AUSTRALIA.
So, I guess my code should be
data add_sub;
set work.merge_treat_con;
if GEOGN in upcase("Australia","Austria") then voi_and_acc=1;
run;
However, the error showing is that
28 data add_sub;
29 set work.merge_treat_con;
30 if GEOGN in upcase("Australia","Austria") then voi_and_acc=1;
_
22
76
ERROR: The right-hand operand must be an array name or a constant value list. The specified name upcase, is not an array.
ERROR 22-322: Syntax error, expecting one of the following: IN, NOTIN.
ERROR 76-322: Syntax error, statement will be ignored.
Could you please help me to sort it out?
Many thanks.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Phil_NZ wrote:
Hi all SAS Users,
I have want to create a variable
voi_and_acc=1
if GEOGN match one of some specific wordsFor example, I have some input specific words like: Argentina, AuStralia
GEOGN is ARGENTINA and AUSTRALIA.
So, I guess my code should be
data add_sub; set work.merge_treat_con; if GEOGN in upcase("Australia","Austria") then voi_and_acc=1; run;
You could also use the FIND function, which allows case insensitive testing of character strings using the 'i' option.
if find(geogn,'Australia','i')>0 or find(geogn,'Austria','i')>0 then ...
Adding on to @Kurt_Bremser 's answer, most SAS interfaces have keyboard shortcuts that allow you to change text that you have selected and convert it to uppercase, magically, right before your eyes! On my Windows 10 computer running Base SAS 9.4, the keyboard shortcut is Ctrl-Shift-U. So if you typed mixed case "Australia" and then select it and Ctrl-Shift-U, now you have "AUSTRALIA".
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
These are literals, so you do not need a function, just write them in uppercase:
if GEOGN in ("AUSTRALIA","AUSTRIA")
And you have to use the list immediately following the IN operator; also, the items in the list MUST be literals (constants).
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Kurt_Bremser wrote:
And you have to use the list immediately following the IN operator
Does it mean that I cannot use
if GEOGN in upcase() or any function but just only if GEOGN in() ?
Warm regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can do this:
if geogn in (upcase('Australia'))
but it would be less typing to do this:
if geogn in ('AUSTRALIA')
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The syntax I'd use would be:
if GEOGN in %upcase(('Australia','Austria'))
This ensures the interpreted string is static, for better performance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Another option is:
if prxmatch('/Australia|Austria/i',GEOGN)
The list of words can easily be expanded, and the final i make the match case-insensitive.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@ChrisNZ wrote:
The syntax I'd use would be:
if GEOGN in %upcase(('Australia','Austria'))
This ensures the interpreted string is static, for better performance.
It's still less typing to put the country names in uppercase to begin with.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I understand the words come as is. GEOGN match one of some specific words
Yes these words could be uppercased too if that doesn't have any negative effect somewhere else
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Phil_NZ wrote:
@Kurt_Bremser wrote:
And you have to use the list immediately following the IN operatorDoes it mean that I cannot use
if GEOGN in upcase() or any function but just only if GEOGN in() ?
Warm regards.
Absolutely. See the documentation of the IN Operator.
The IN is set up by the data step or SQL compiler at compile time, so it cannot have variable expressions or functions in it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Phil_NZ wrote:
Hi all SAS Users,
I have want to create a variable
voi_and_acc=1
if GEOGN match one of some specific wordsFor example, I have some input specific words like: Argentina, AuStralia
GEOGN is ARGENTINA and AUSTRALIA.
So, I guess my code should be
data add_sub; set work.merge_treat_con; if GEOGN in upcase("Australia","Austria") then voi_and_acc=1; run;
You could also use the FIND function, which allows case insensitive testing of character strings using the 'i' option.
if find(geogn,'Australia','i')>0 or find(geogn,'Austria','i')>0 then ...
Adding on to @Kurt_Bremser 's answer, most SAS interfaces have keyboard shortcuts that allow you to change text that you have selected and convert it to uppercase, magically, right before your eyes! On my Windows 10 computer running Base SAS 9.4, the keyboard shortcut is Ctrl-Shift-U. So if you typed mixed case "Australia" and then select it and Ctrl-Shift-U, now you have "AUSTRALIA".
Paige Miller