I get bad results because they don't wait for each other.
The result is different from the one I egt when I run both datasteps one after another.
proc cas;
function doesTableExist(casLib,casTable);
table.tableExists result=r status=rc / caslib=casLib table=casTable;
tableExists = dictionary(r, "exists");
return tableExists;
end func;
source myDataStep;
data casuser.origin_filtered_by_time;
set &fname.;
if timestamp >= input("&last_start_date.", datetime20.);
keep timestamp var1;
run;
endsource;
source myDataStep1;
data casuser.result_groups_temp / sessref="mySession"
single=yes;
set casuser.origin_filtered_by_time;
by timestamp var1;
retain group_id;
if lag(var1) ^= var1 then group_id + 1;
if first.timestamp;
run;
endsource;
/* check whether the process has been carried out at least once */
tableExists_watchdog = doesTableExist("&liby", "&casy_watchdog");
/* in that case, proceed with the following steps */
if tableExists_watchdog ^=0 then do;
dataStep.runCode result=r status=rc /
code=myDataStep;
dataStep.runCode result=r status=rc /
code=myDataStep1;
run;
In what way is the result different from your expected result?
The final output table had less entries.
It seemed to me that the second data step didn't wait for the first one to complete. As if it started setting the input table=output table from the first data step before it had all rows written to table.
In your second DATA step, this statement:
if first.timestamp;
ensures that only the first record for each timestamp group is output. So the output data set from the second data step (casuser.result_groups_temp) will most likely have significantly fewer observations than the input data set (casuser.origin_filtered_by_time).
I emulated your process by loading the sashelp.cars dataset to my casuser caslib, and using it in a simplified form of your program. It all worked exactly as I would have expected...
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.