Hey everyone,
I have a table, TEST, and I want to update the TEST.status = "submitted" if TEST.ID exists in another table I have of IDs
I wrote this code below in proc sql but for some reason the IN keyword wont highlight and I am not getting the expected result
proc sql;
update work.test
set status = "submitted"
where id in
(select ID from work.list_of_IDs);
quit;
It runs without errors but I get the note that no rows have been updated.
If anyone knows what is going wrong or can offer a solution I would really appreciate it, I have been struggling with this for some time now.
"highlight"? Are you talking about something the editor is doing to give you a little help it finding typos? I wouldn't worry about whether the editor knows how to highlight your code or not.
Test whether there are in fact any observations that need updating.
proc sql;
select count(*) as number_to_update
from work.test
where id in (select ID from work.list_of_IDs)
;
quit;
Perhaps none of the values of ID in LIST_OF_IDS match the values of ID in TEST.
Yeah I actually realized my list_of_IDs was incorrect, some leading zeros were truncated in excel and that was causing the issue. Thanks for the help!!
@gmuersch wrote:
Yeah I actually realized my list_of_IDs was incorrect, some leading zeros were truncated in excel and that was causing the issue. Thanks for the help!!
Excel is where data goes to die. Or at least get managled into unrecognizable junk.
Do you have an Excel file or a CSV file?
@gmuersch wrote:
Yeah I actually realized my list_of_IDs was incorrect, some leading zeros were truncated in excel and that was causing the issue. Thanks for the help!!
It should work. Make sure the IDs are exactly the same in both tables. Watch for leading spaces or zeros if the IDs are character, or fields that differ but look the same only because of formats.
"IN" used that way is an operator and basically none of the operators like: + * - / OR AND NOT > < are highlighted. So that isn't to be worried about at all. Depending on SAS modules you'll find many key elements that are not highlighted and sometimes ones reported as "unknown keywords" just because the Editor hasn't been told to see them yet.
Small example data of your values may provide some insight. Only provide examples of the variables used.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: