The error message is clear: SASGrid doesn't exist in the environment where you're running the code OR you are using a metadata user that doesn't have read access to it.
If you believe that SASGrid does exist and your metadata user has sufficient privileges to "see" it then I suggest you create a SAS metadata query that lists all SAS app servers defined in metadata and run it the same way than your initial script. This will tell you with certainty what exists and is accessible (and I'm pretty sure it won't list SASGrid).
But before spending this time: Have you already tried and executed your script searching for SASApp? (just run your code with everything after the step that throws the current error removed).
And just as a remark not related to your current challenge:
Not sure why the sample code you've got needs to query for existence of the application server for every single row in your driver table. I'd modify the code like below so it only queries it once.
data _null_;
/* Initialize variables. */
length type id appuri diruri $ 255;
/* Define query for context. */
appobj = "omsobj:ServerContext?@Name='&appcontext'";
/* Check for the existence of the context. */
rc=metadata_resolve(appobj,type,id);
/* If the context doesn't exist, throw an error and end the program. */
if rc ne 1 then
do;
put "ERROR: A single context named &appcontext not found.";
stop;
end;
do until(last);
/* Read in the data set of deployment directories. */
set depdirs end=last;
/* For each one, create the directory object as a child of the context defined above. */
rc=metadata_newobj("Directory",diruri,Name,"Foundation",appobj,"DataPackages");
/* Add the attribute defining the path. */
rc=metadata_setattr(diruri,"DirectoryName",Path);
/* Add some required attributes. */
rc=metadata_setattr(diruri,"UsageVersion","0");
rc=metadata_setattr(diruri,"IsRelative","0");
call missing (diruri);
end;
run;
... View more