Hi,
I have this code that works:
%let caslib = AAAA;
%let libname=SASHELP;
%let table=CARS;
cas mysess sessopts=(caslib=&caslib.);
caslib _ALL_ assign;
/* load */
proc casutil;
load data=&libname..&table.
outcaslib="&caslib." casout="&table." REPLACE;
run;
proc cas;
loadactionset / actionSet="dataDiscovery";
run;
dataDiscovery.profile result=r / table={name="&table."},
casOut={name="Profilazione", replace=true};
run;
but if i use this it gives me an error:
%let caslib = AAAA;
%let libname=SASHELP;
%let table=CARS;
cas;
libname &caslib. cas caslib=&caslib.;
/* load */
proc casutil;
load data=&libname..&table.
outcaslib="&caslib." casout="&table." REPLACE;
run;
proc cas;
loadactionset / actionSet="dataDiscovery";
run;
dataDiscovery.profile result=r / table={name="&table."},
casOut={name="Profilazione", replace=true};
run;
I just changed the bold part. Instead of allocating all CAS I allocate only one.
The error are:
ERROR: Could not connect to the Hadoop cluster.
ERROR: Table 'CARS' could not be loaded.
ERROR: Failure opening table 'CARS': A table could not be loaded.
ERROR: The action stopped due to errors.
Thanks
Luca
I think it's because you are not specifying the caslib in the dataDiscovery.profile action.
In CAS, you have what's called an active caslib. The active caslib is like your current working directory. If you do not specify a caslib, CAS will use the active caslib. By default, the Casuser caslib is typically the active caslib. You can check with this code:
proc cas;
sessionProp.getSessOpt / name = 'caslib';
quit;
/* results */
{caslib=CASUSER(user-name)}
In your working code you changed the active caslib in the CAS statement to the AAAA caslib. Now if you specify a CAS table without specifying where the CAS table is, it'll use AAAA by default.
cas mysess sessopts=(caslib=&caslib.);
Then you load the sashelp.cars SAS data set into memory in the AAAA caslib. Now this data set was loaded to the AAAA caslib (whatever data source that connects to. Could be a database, path, cloud, etc.). In the CASUTIL code you specified the outcaslib parameter, indicating which caslib you want to load this table to. If you didn't specify the outcaslib parameter, it would use the active caslib.
proc casutil;
load data=&libname..&table.
outcaslib="&caslib." casout="&table." REPLACE;
run;
In your dataDiscover.profile action you don't specify where the CAS table you want is. So SAS will use the active caslib by default. In your working code the active caslib is AAAA since you set it in your CAS statement. In the code that's erroring out my guess is the active caslib is Casuser, and the CARS table doesn't exist in Casuser.
dataDiscovery.profile result=r / table={name="&table."}, /* <--where should I look for this table??? SAS will look in the active caslib */
casOut={name="Profilazione", replace=true}; /* <--where should I create this table??? SAS will use the active caslib */
run;
I recommend always specifying the caslib and not relying on the active caslib, even though it's not always required. It's very easy to change the active caslib accidently, and this could cause issues like this. Being explicit avoids these issues and honestly makes your code easier to read.
Here is how I would type out the action.
proc cas;
loadactionset / actionSet="dataDiscovery";
run;
dataDiscovery.profile result=r /
table={
name="&table.",
caslib="&caslib" /*Specify input caslib. If this is omitted, the active caslib is used */
},
casOut={
name="Profilazione",
caslib="&caslib", /*Specify output caslib. If this is omitted, the active caslib is used */
replace=true
};
quit;
I also have a series of blogs on CAS actions. Feel free to check out them out: https://blogs.sas.com/content/sgf/2021/08/06/cas-action-a-series-on-fundamentals/
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.