data casuser.test;
format timestamp datetime20.;
do i=1 to 100;
timestamp=intnx('dtminutes', datetime(), i);
output;
end;
drop i;
run;
proc cas;
simple.summary result=sumres /
subset={'min', 'max'}, inputs={{name='timestamp', format='datetime20.' nfl=30, nfd=30}},
attributes={{name='timestamp', format='datetime20.' nfl=30, nfd=30}},
table={caslib="casuser",name="test"};
print sumres;
run;
Hey @acordes! One way to do this is to use the putn function on the Min/Max values in the result. For example:
proc cas;
simple.summary result=sumres /
subset={'min', 'max'}, inputs={{name='timestamp', format='datetime20.' nfl=30, nfd=30}},
attributes={{name='timestamp', format='datetime20.' nfl=30, nfd=30}},
table={caslib="casuser",name="test"};
print 'Min:' putn(sumres.summary[1, 'Min'], datetime20.);
print 'Max:' putn(sumres.summary[1, 'Max'], datetime20.);
run;
Another option is to output the table and use table.fetch:
proc cas;
simple.summary result=sumres /
subset={'min', 'max'}, inputs={{name='timestamp', format='datetime20.' nfl=30, nfd=30}},
attributes={{name='timestamp', format='datetime20.' nfl=30, nfd=30}},
table={caslib="casuser",name="test"}
casout={caslib="casuser",name="outsum",replace=True};
table.fetch /
table='outsum'
fetchvars={{name='_min_', format='datetime20.'}
{name='_max_', format='datetime20.'}
};
run;
Or, if you want to use a CAS-powered PROC, you can try MDSUMMARY and then print it with PROC PRINT:
proc mdsummary data=casuser.test;
var timestamp;
output out=casuser.outsum;
run;
proc print data=casuser.outsum;
format _min_ _max_ datetime20.;
var _min_ _max_;
run;
Hey @acordes! One way to do this is to use the putn function on the Min/Max values in the result. For example:
proc cas;
simple.summary result=sumres /
subset={'min', 'max'}, inputs={{name='timestamp', format='datetime20.' nfl=30, nfd=30}},
attributes={{name='timestamp', format='datetime20.' nfl=30, nfd=30}},
table={caslib="casuser",name="test"};
print 'Min:' putn(sumres.summary[1, 'Min'], datetime20.);
print 'Max:' putn(sumres.summary[1, 'Max'], datetime20.);
run;
Another option is to output the table and use table.fetch:
proc cas;
simple.summary result=sumres /
subset={'min', 'max'}, inputs={{name='timestamp', format='datetime20.' nfl=30, nfd=30}},
attributes={{name='timestamp', format='datetime20.' nfl=30, nfd=30}},
table={caslib="casuser",name="test"}
casout={caslib="casuser",name="outsum",replace=True};
table.fetch /
table='outsum'
fetchvars={{name='_min_', format='datetime20.'}
{name='_max_', format='datetime20.'}
};
run;
Or, if you want to use a CAS-powered PROC, you can try MDSUMMARY and then print it with PROC PRINT:
proc mdsummary data=casuser.test;
var timestamp;
output out=casuser.outsum;
run;
proc print data=casuser.outsum;
format _min_ _max_ datetime20.;
var _min_ _max_;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.