My code works for 1 computed column, but I cannot manage to get a second column attached.
@BrunoMueller , any idea?
My code is based on
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.2/proccas/p1ioxwkh6crvhrn1alvzokmxsuyr.htm
data casuser.cars;
set sashelp.cars;
if horsepower le 340;
run;
%let casy1=cars;
%let liby1=casuser;
proc cas;
simple.distinct result=dist /
table={name="&casy1.", caslib="&liby1."};
run;
table.recordCount result=count /
table={name="&casy1.", caslib="&liby1."};
run;
nrows=findtable(count)[1,1];
computedcolumn=findtable(dist).
compute({"n_rows", "number of rows", best12.}, nrows)
[, {"Column", "ndistinct","nmiss", "n_rows"}];
subset= computedcolumn;
saveresult subset dataout=work.&casy1.;
run;
simple.distinct result=dist /
table={name="&casy1.", caslib="&liby1."};
run;
table.recordCount result=count /
table={name="&casy1.", caslib="&liby1."};
run;
nrows=findtable(count)[1,1];
computedcolumn=findtable(dist).
compute({"filter", "filter criteria", $200.},
"if horsepower le 340")
[, {"Column", "ndistinct","nmiss", "filter"}];
subset= computedcolumn;
saveresult subset dataout=work.filt_&casy1.;
run;
simple.distinct result=dist /
table={name="&casy1.", caslib="&liby1."};
run;
table.recordCount result=count /
table={name="&casy1.", caslib="&liby1."};
run;
nrows=findtable(count)[1,1];
computedcolumn=findtable(dist).
compute({{"n_rows", "number of rows", best12.}, nrows} ,
{{"filter", "filter criteria", $200.},
"if horsepower le 340" })
[, {"Column", "ndistinct","nmiss", "n_rows", "filter"}];
subset= computedcolumn;
saveresult subset dataout=work.&casy1._2cols;
run;
run;
Hi
According to the doc (https://documentation.sas.com/doc/en/pgmsascdc/default/caslpg/p1xhd1xslkblfan16lcboym5nle9.htm) for the result table compute operator, it is only possible to have one column added. To add a second column you do need a second statement, see example below.
data casuser.cars;
set sashelp.cars;
if horsepower le 340;
run;
%let casy1=cars;
%let liby1=casuser;
proc cas;
simple.distinct result=dist /
table={name="&casy1.", caslib="&liby1."};
run;
table.recordCount result=count /
table={name="&casy1.", caslib="&liby1."};
run;
nrows=findtable(count)[1,1];
computedcolumn=findtable(dist).
compute({"n_rows", "number of rows", best12.}, nrows);
subset= computedcolumn;
saveresult subset dataout=work.&casy1.;
print subset;
run;
computedColumn = computedColumn.compute(
{"filter", "where clause", $4096.}, "make = 'Europe'"
);
print computedColumn;
describe computedColumn;
run;
saveresult computedColumn dataout=work.final ;
run;
quit;
Hi
According to the doc (https://documentation.sas.com/doc/en/pgmsascdc/default/caslpg/p1xhd1xslkblfan16lcboym5nle9.htm) for the result table compute operator, it is only possible to have one column added. To add a second column you do need a second statement, see example below.
data casuser.cars;
set sashelp.cars;
if horsepower le 340;
run;
%let casy1=cars;
%let liby1=casuser;
proc cas;
simple.distinct result=dist /
table={name="&casy1.", caslib="&liby1."};
run;
table.recordCount result=count /
table={name="&casy1.", caslib="&liby1."};
run;
nrows=findtable(count)[1,1];
computedcolumn=findtable(dist).
compute({"n_rows", "number of rows", best12.}, nrows);
subset= computedcolumn;
saveresult subset dataout=work.&casy1.;
print subset;
run;
computedColumn = computedColumn.compute(
{"filter", "where clause", $4096.}, "make = 'Europe'"
);
print computedColumn;
describe computedColumn;
run;
saveresult computedColumn dataout=work.final ;
run;
quit;
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.